简体   繁体   中英

saving NSDate using NSUserDefaults

Is there any other solutions in iOS for saving the NSDate in one ViewController and showing it in a label in another ViewController rather than NSUserDefaults? I have 2 viewControllers in my project which one of them is DatePicker and another is a normal ViewController with a label.I want to show the time with DatePicker chosen in that label and I use NSUserDefaults.I am curios is there any other solution for this matter?Thanks in advance.

Core Data can be used instead of NSUserDefaults. Core Data is better, though, for larger amounts of data, so for your case, NSUserDefaults is the best option.

Core data is great for relationships and has a nice interface for adding entities and relationships.

It uses key value coding (setValue:ForKey: like NSDictionary) and objects from core data are subclasses of NSManagedObject.

Here is a nice tutorial: http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started

You can use a singleton class (eg DataManager ), and you could keep the selected date here if you have no direct segue between these 2 UIViewControllers . if you do, just add a property and set it when you present the controller. However, these won't persist between app launches, so for that you would need the NSUserDefaults

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM