[Solved] What am I doing wrong with this NSMutableArray of structs in NSUserDefaults? “attempt to insert non-property list object”


From the NSUserDefaults Class Reference:

A default object must be a property list, that is, an instance of (or
for collections a combination of instances of): NSData, NSString,
NSNumber, NSDate, NSArray, or NSDictionary. If you want to store any
other type of object, you should typically archive it to create an
instance of NSData.

The exception occurs because you try to store an NSValue object.
To store the struct as NSData, use

NSData *p1data = [NSData dataWithBytes:&p1 length:sizeof(p1)];

and extract it from NSData with

[p1data getBytes:&p1 length:sizeof(p1)];

solved What am I doing wrong with this NSMutableArray of structs in NSUserDefaults? “attempt to insert non-property list object”