ios 沙盒 preference 首选项 数据存储

转自: http://www.maxiaoguo.com/clothes/231.html
- (IBAction)save {
    // 1.利用NSUserDefaults,就能直接访问软件的偏好设置(Library/Preferences)
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    // 2.存储数据
    [defaults setObject:@"mj" forKey:@"account"];
    [defaults setObject:@"123" forKey:@"pwd"];
    [defaults setInteger:10 forKey:@"age"];
    [defaults setBool:YES forKey:@"auto_login"];
    
    // 3.立刻同步
    [defaults synchronize];
}

- (IBAction)read {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    NSString *account = [defaults objectForKey:@"account"];
    BOOL autoLogin = [defaults boolForKey:@"auto_login"];
    NSLog(@"%@ -- %d", account, autoLogin);
}

你可能感兴趣的:(ios 沙盒 preference 首选项 数据存储)