标签:
/** * NSUserDefaults可以进行轻量级的数据存储 * NSUserDefaults支持的数据类型: NSString, NSNumber, NSDate, NSArray, * NSDictionary */ //初始化NSUserDefaults NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; //存储BOOL类型 [defaults setBool:YES forKey:@"fisrtLaund"]; //存储对象 [defaults setObject:@"LF" forKey:@"name"]; //存储Integer类型 [defaults setInteger:23 forKey:@"age"]; //同步到磁盘 [defaults synchronize]; //NSUserDefaults的读取 BOOL isFirst = [defaults boolForKey:@"fisrtLaund"]; id name = [defaults objectForKey:@"name"]; NSInteger age = [defaults integerForKey:@"age"]; NSLog(@"%d--%@--%ld",isFirst,name,age); //删除数据 [defaults removeObjectForKey:@"name"]; NSLog(@"%@",[defaults objectForKey:@"name"]);
标签:
原文地址:http://www.cnblogs.com/lantu1989/p/5205616.html