Created
October 13, 2012 10:13
-
-
Save caoer/3884047 to your computer and use it in GitHub Desktop.
Objective-C: Save object to NSUserDefault.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (MyCustomObject *)getObject { | |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
NSData *MyCustomObjectEncodedObject = [defaults objectForKey:kMyCustomObjectKEY]; | |
MyCustomObject *MyCustomObject = (MyCustomObject *)[NSKeyedUnarchiver unarchiveObjectWithData: MyCustomObjectEncodedObject]; | |
return MyCustomObject; | |
} | |
- (void)setMyCustomObject:(MyCustomObject *)MyCustomObject { | |
NSData *MyCustomObjectEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:MyCustomObject]; | |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
[defaults setObject:MyCustomObjectEncodedObject forKey:kMyCustomObjectKEY]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment