about 11 years ago
NSUserDefaults is very useful, if you want to save less data and want to access that data whenever you open the application. This data does not delete even after closing the app.
To save data in NSUserDefaults
- NSUserDefaults *usr = [NSUserDefaults standardUserDefaults];
- [usr setObject:userNameText.text forKey:@"user"];
- [usr setObject:passwordText.text forKey:@"password"];
- [usr synchronize];
NSUserDefaults *usr = [NSUserDefaults standardUserDefaults]; [usr setObject:userNameText.text forKey:@"user"]; [usr setObject:passwordText.text forKey:@"password"]; [usr synchronize];
To access data from NSUserDefaults
- NSUserDefaults *usr = [NSUserDefaults standardUserDefaults];
- NSString *user = [usr objectForKey:@"user"];
- NSString *pass = [usr objectForKey:@"password"];
NSUserDefaults *usr = [NSUserDefaults standardUserDefaults]; NSString *user = [usr objectForKey:@"user"]; NSString *pass = [usr objectForKey:@"password"];
0 Comment(s)