所以我使用一个 plist 文件来存储一个 NSMutableArray 并且当添加一个对象时也将它保存到那个 plist 文件中。但我收到此错误:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:1];
_prsPath = [documentsDirectory stringByAppendingPathComponent:@"records.plist"];
prs = [[NSMutableArray alloc] initWithContentsOfFile:_prsPath];
if (prs == nil) {
prs = [NSMutableArray array];
}
在“addObject”之后:
[prs writeToFile:_prsPath atomically:YES];
用这个代码挣扎了几个小时。
提前致谢!