Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSUserDefaults vs NSCoding

When saving small amounts of data from within my App is it better to use NSUserDefaults or NSCoding? Right now I use NSCoding (encodeWithCoder/initWithCoder, etc.) but it appears that NSUserDefaults might be simpler. My total data is about a variety of Ints/Strings/MutableArray, only about a few dozen total.

like image 626
wayneh Avatar asked Apr 11 '14 17:04

wayneh


1 Answers

I assume that by NSCoding you mean "saving objects to files after serializing them with NSCoding APIs". Although both approaches are valid for primitive data types, the NSUserDefaults approach gets more difficult once you start serializing objects with complex structures.

In contrast, saving data of NSCoding classes to files offers high degree of flexibility in terms of object structure. If you know that you are not going to need this flexibility in the future, go with NSUserDefaults; if you are not sure, stay with the files.

like image 99
Sergey Kalinichenko Avatar answered Nov 15 '22 16:11

Sergey Kalinichenko