标签:roo root try user exce 方法 test 读数 standard
NSCoding
协议encodeWithCoder
和initWithCoder
方法先把类的instance archive成NSData,然后存起来
TGTest *tt = [TGTest new];
tt.num = 3;
NSData *dd = [NSKeyedArchiver archivedDataWithRootObject:tt];
[[NSUserDefaults standardUserDefaults] setObject:dd forKey:@"objtest"];
读数据时,读出NSData,然后unarchive得到instance。
NSData *dd = [[NSUserDefaults standardUserDefaults] objectForKey:@"objtest"];
@try
{
TGTest *tt= [NSKeyedUnarchiver unarchiveObjectWithData:dd];
}
@catch (NSException *exception)
{
NSLog(@"%@",exception);
}
@finally
{
}
标签:roo root try user exce 方法 test 读数 standard
原文地址:http://www.cnblogs.com/huahuahu/p/NSUserDefault-cun-chu-lei.html