Reputation: 3
I am developing an app and needs to save arrays, but I'm not sure how I can do it. Does anyone know how I could save and load arrays in Xcode Objective-c?
Thanks!
Upvotes: 0
Views: 66
Reputation: 1152
That's a very broad question, but here is a very simple answer.
To save your array to file:
[NSKeyedArchiver archiveRootObject:array toFile:fileName];
To load your array from that file:
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:fileName];
These calls depend on the fact that NSArray implements NSCoding (through NSSecureCoding).
Upvotes: 2