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
, orNSDictionary
. If you want to store any other type of object, you should typically archive it to create an instance ofNSData
.
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)];