我有一个包含不同的对象,如字符串的UIImage等 它们进行排序这样的可变数组:对象保存阵列性能的plist
例子:
BugData *bug1 = [[BugData alloc]initWithTitle:@"Spider" rank:@"123" thumbImage:[UIImage imageNamed:@"1.jpeg"]];
...
...
NSMutableArray *bugs = [NSMutableArray arrayWithObjects:bug1,bug2,bug3,bug4, nil];
所以基本上它是具有不同属性的对象的数组。
我试图用下一个代码保存单个字符串到一个文件,它的工作正常,但是当我尝试与对象保存数组时,我得到一个空的plist文件。
NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString * path = [docsDir stringByAppendingPathComponent:@"data.plist"];
NSLog(@"%@",bugs); //Making sure the array is full
[bugs writeToFile:path atomically:YES];
我在做什么错?
你有没有在你的'Bug'类实现'NSCoding'? –