Suppose the objects contained in your array conform to the NSCoding protocol, you can use
// let take the NSString as example NSArray *array = @[@"foo", @"bar"]; [[NSUserDefaults standardUserDefaults] setObject: [NSKeyedArchiver archivedDataWithRootObject:array] forKey:@"annotationKey"]; NSArray *archivedArray = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] objectForKey:@"annotationKey"]] ;
If they comply with the NSCopying protocol, then
// let take the NSString as example NSArray *array = @[@"foo", @"bar"]; [[NSUserDefaults standardUserDefaults] setObject: array forKey:@"annotationKey"]; NSArray *archivedArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"annotationKey"] ;
EDIT
Well, it may not work for NSArray objects that conform to the NSCopying protocol, but it may work for objects that conform to the NSCoding protocol, as pointed out by Brad Larson in the following answer:
Saving custom objects in NSMutableArray in NSUserDefaults
source share