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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With