@implementation标签:forKey,Preferences,void,IOS,defaults,NSUserDefaults,password From: https://blog.51cto.com/u_15907570/5925328
- (void)viewDidLoad
{
[superviewDidLoad];
self read];
}
读取偏好设置
- (void)read {
NSUserDefaults *defaults = [NSUserDefaultsstandardUserDefaults];
NSString *useranme = [defaults objectForKey:@"username"];
NSString *password = [defaults objectForKey:@"password"];
BOOL autoLogin = [defaults boolForKey:@"auto_login"];
NSLog(@"%@-%@-%i",useranme, password, autoLogin);
}
存储偏好设置
- (void)save {
// NSUserDefaults关联着沙盒中的Preferences文件夹
NSUserDefaults *defaults = [NSUserDefaultsstandardUserDefaults];
[defaults setObject:@"jamesWong" forKey:@"username"];
setObject:@"123" forKey:@"password"];
setBool:YES forKey:@"auto_login"];
// 将数据同步到Preferences文件夹中
synchronize];
}
@end