It looks like you will need to archive your array, either with NSKeyedArchiver
or NSArchiver
. If you first archive the array into a NSData object:
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:myArray];
You can then store that data in NSUserDefaults like so:
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"myArray"];
To load the array, use:
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"myArray"];
NSArray *myArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
If you want to use an NSMutableArray then just replace any NSArray
occurrences in the code above with NSMutableArray
. OR you can just NSMutableArray *myMutableArray = [myArray mutableCopy]
will give you a NSMutableArray to work with.
But then hey, if you are going to the trouble of making it NSCoding compliant, why not just archive it to a file?
The documentation that made me think that you will need to use an archiver is here so that you can check for yourself.