我正在尝试将巨大的NSArray保存到文件中然后检索它......
NSURL *documentsDirectory =
[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
NSURL *fileURL = [documentsDirectory
URLByAppendingPathComponent:@"scorecards.dgs"];
NSMutableArray *savedArrayOfScorecards = [NSMutableArray arrayWithContentsOfURL:fileURL];
[savedArrayOfScorecards addObject:currentScoreCard];
[savedArrayOfScorecards writeToURL:fileURL atomically:YES];
NSMutableArray *mynewArray = [NSMutableArray arrayWithContentsOfURL:fileURL];
NSLog(@"%@, %@",[[mynewArray objectAtIndex:0] objectForKey:@"info"], course);
NSLog回来了......
(null), BridgeMill
应该在逗号的两边返回哪个BridgeMill。但阵列不会保存......
答案 0 :(得分:2)
检查它是否正确保存:
if([savedArrayOfScorecards writeToURL:fileURL atomically:YES])
{
NSLog(@"Was saved");
}
else
{
NSLog(@"Houston we have a problem...");
}
- (BOOL)writeToURL:(NSURL *)aURL atomically:(BOOL)atomically
您还可以使用它来检查发生了什么:
- (BOOL)writeToURL:(NSURL )aURL选项:(NSDataWritingOptions)掩码错误:(NSError * )errorPtr
答案 1 :(得分:0)
什么班级是course
?
writeToURL
仅支持可转换为plist格式的类型。这些类型是NSString,NSData,NSArray或NSDictionary。
如果您的NSArray中有其他类型,则必须archive the array。