One of the advantages of CoreData is that your object will be an NSManagedObject with properties. This means that when you get or set values, you will have autocomplete to help you with property names. It also makes the code more readable.
Meanwhile, with NSUserDefaults, you should always use key-value for access, using strings for the key.
i.e:.
myGlobalSettingsObject.lastLoginTime = @(now);
against.
[[NSUserDefaults standardUserDefaults] setValue:@(now) forKey:@"lastLoginTime"];
What to do if you accidentally make a reservation when installing the key somewhere? The compiler will not warn you. What if someone puts the wrong type somewhere? The compiler will not warn you.
eg:.
[[NSUserDefaults standardUserDefaults] setValue:@"now" forKey:@"lastLoginTiem"]; ^ ^ ^^^^
... will not cause a warning or error during assembly ... is dangerous!
Other advantages of using NSManagedObject are that it can have validation; it can provide non-empty values; it can have custom retrieval and customization methods that you can use to make cool stuff; it can handle automatic migration if you change something about how all values ββare stored; and its data model becomes part of your repository, so you can easily track change history.
Meanwhile, NSUserDefaults is fast and dirty, and great for basic small applications, but it's very unusual. Great for a small application, but if you have a huge application, it becomes difficult to manage compared to using Core Data.
The only possible thing about NSUserDefaults is that if your application needs to remove the CoreData repository or you donβt want to be nervous when implementing Thread-safe CoreData, this reduces maintenance in this regard.
CommaToast May 05 '16 at 17:54 2016-05-05 17:54
source share