[[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@"myArray"];
If I make an array of custom objects conform to the NSCoding protocol, then does the above work? Do I have to make both the custom class and the view controller that holds the array of custom objects conform to the NSCoding protocol or just the custom class? Do I have to use NSKeyedArchiver somewhere?
It looks like you will need to archive your array, either with
NSKeyedArchiverorNSArchiver. If you first archive the array into a NSData object:You can then store that data in NSUserDefaults like so:
To load the array, use:
If you want to use an NSMutableArray then just replace any
NSArrayoccurrences in the code above withNSMutableArray. OR you can justNSMutableArray *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.