Correct way to save/serialize custom objects in iOS

后端 未结 4 1963
北海茫月
北海茫月 2020-11-29 18:29

I have a custom object, a UIImageView subclass which has a few gestureRecognizer objects.

If I have a number of these objects stored in a

4条回答
  •  孤街浪徒
    2020-11-29 19:15

    //store the array
    [NSKeyedArchiver archiveRootObject:myArray toFile:@"someFile"];
    
    //load the array
    NSMutableArray* myArray = [NSKeyedUnarchiver unarchiveObjectWithFile:@"someFile"];
    

    Official References.

    Note that when the array contains custom object types, you must ensure your type conforms to the NSCoding Protocol before this will work.

提交回复
热议问题