I want to save My Data Type temporary in NSUserDefault. this data later pull back.
I tried to following code.
MyObject *myObject = [[MyObject alloc] init];
[[NSUserDefaults standardUserDefaults] setObject:myObject forKey:@"kMyObject"];
but console show to text me following message.
-[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<MyObject: 0x4aadb0>' of class 'MyObject'. Note that dictionaries and arrays in property lists must also contain only property values.
I can ignore these messages and to force pull out from NSUserDefault.
MyObject *getObject = [[NSUserDefaults standardUserDefaults] objectForKey:@"kMyObject"];
but, not give back original data. (I’ve Checked the NSLog, returns Null.)
How to solve this problem? I only prefer save to NSUserDefaults. not recommended to me using CoreData.
Many Developer recommend to NSKeyedArchiver Taking advantage of the concept. but it must implement protocols to NSCopy NSCoding and because some can be complex. More than that there is an easier way.
refer a following code.
Save
Load