NSUserDefault 存储
今天用到NSUserDefault的时候,一直以为[[NSUserDefaults standardUserDefaults] setObject:array forKey:@"testInfo"] ;就算存储好了,再[[NSUserDefaults standardUserDefaults] arrayForKey:@"testInfo"]就算取出来,可是发现重启动程序,关键字testInfo对应的竟然是空,仔细查下资料,发现自己太大意了,忘了写到disk里面了![[NSUserDefaults standardUserDefaults] synchronize]; 涨学问了又。。。呵呵!!!!
下面贴出代码:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@"111" forKey:@"myTest"];
[defaults synchronize];
NSString *testStr = [defaults objectForKey:@"myTest"];
NSLog(@"testStr is: %@",testStr);