iOS开发—归档一个Model数组

2017-01-14 10:20:25来源:http://www.jianshu.com/p/fb7520c0b772作者:支梦召人点击

在这里为大家共享一下在开发中遇到的问题,而后又找到了比较不错的答案,虽然是摘抄的,但我相信知识本来就是用来共享的,希望我的这番整理能够给更多的人带来方便。


self.title = @"复杂对象归档";
Person *personA = [[Person alloc] init];
personA.name = @"张三";
personA.age = 20;
personA.sex = @"男";
Person *personB = [[Person alloc] init];
personB.name = @"李四";
personB.age = 15;
personB.sex = @"女";
Person *personC = [[Person alloc] init];
personC.name = @"王五";
personC.age = 30;
personC.sex = @"男";
NSString *paths =[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
NSLog(@"Caches: %@", paths);
NSMutableArray *personsArr = [NSMutableArray arrayWithObjects:personA, personB, personC, nil];
NSString *personsArrPath = [paths stringByAppendingString:@"/personsArr.plist"];
[personsArr writeToFile:personsArrPath atomically:YES];
NSLog(@"%@", personsArrPath);



最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台