偏好设置

- (IBAction)save {

// 1.利用NSUserDefaults,就能直接访问软件的偏好设置(Library/Preferences)

NSUserDefaults*defaults = [NSUserDefaultsstandardUserDefaults];

// 2.存储数据

[defaultssetObject:@"mj"forKey:@"account"];

[defaultssetObject:@"123"forKey:@"pwd"];

[defaultssetInteger:10forKey:@"age"];

[defaultssetBool:YESforKey:@"auto_login"];

// 3.立刻同步

[defaultssynchronize];

- (IBAction)read {

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSString *account = [defaults objectForKey:@"account"];

BOOL autoLogin = [defaults boolForKey:@"auto_login"];

NSLog(@"%@ -- %d", account, autoLogin);

你可能感兴趣的:(偏好设置)