user3237532
user3237532

Reputation: 3

Save and load arrays - Objective c

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

Answers (1)

bgfriend0
bgfriend0

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

Related Questions