NSUserDefaults
is backed by a property list. Alas, proprety lists cannot contain serialised objects. Quoting from the manual:
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
You'll have to create your own serialised data file for saving the object directly, or serialise the objects as one of the allowed types. Annoyingly, NSUserDefaults
doesn't call encodeWithCoder
- it just screens the object type passed to setObject:forKey:
. The best bet is to either serialise the fields of the HotelDC
yourself, or archive the object to an NSData
instance and store that.