Created
May 17, 2013 22:17
-
-
Save maltzsama/5602351 to your computer and use it in GitHub Desktop.
Saving n Retrieving Data Using NSUserDefaults
This file contains hidden or 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
| //Saving | |
| NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; | |
| // saving an Object | |
| [prefs setObject:Object forKey:@"keyObject"]; | |
| // saving an NSInteger | |
| [prefs setInteger:42 forKey:@"keyInt"]; | |
| // saving a Double | |
| [prefs setDouble:3.1415 forKey:@"keyDouble"]; | |
| // saving a Float | |
| [prefs setFloat:1.2345678 forKey:@"keyFloat"]; | |
| // This is suggested to synch prefs, but is not needed | |
| [prefs synchronize]; | |
| Retrieving | |
| NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; | |
| // getting an NSString | |
| NSString *myString = [prefs stringForKey:@"keyObject"]; | |
| // getting an NSInteger | |
| NSInteger myInt = [prefs integerForKey:@"keyInt"]; | |
| // getting an Float | |
| float myFloat = [prefs floatForKey:@"keyFloat"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment