Iphone 写入文件失败

Iphone 写入文件失败,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我试图将NSMutableArray写入文件,但每次都失败。我相信我所说的道路是正确的。还有什么问题 for (int i=1; i<=10/*[self getcurrentnumber]*/;i++) { [mutablearray addObject:[self convertJSONtoDictionary:[self generateJSONforcomic:[NSNumber numberWithInt:i]]]]; NSLog(@"Iteration %i",

我试图将NSMutableArray写入文件,但每次都失败。我相信我所说的道路是正确的。还有什么问题

for (int i=1; i<=10/*[self getcurrentnumber]*/;i++)
{
    [mutablearray addObject:[self convertJSONtoDictionary:[self generateJSONforcomic:[NSNumber numberWithInt:i]]]];
    NSLog(@"Iteration %i",i);
}
NSLog(@"Done %.0u",[mutablearray count]);

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];
NSString *location = [libraryDirectory stringByAppendingString:@"/Comics.txt"];
NSLog(location);
[mutablearray writeToFile:location atomically:YES];
if(![mutablearray writeToFile:location atomically:YES])NSLog(@"Fail");

for(int i=1;i数组中可能有某种类型的对象无法写入plist(默认情况下是数组的存储机制)

常见的示例是任何自定义类、UIImage或NSNull(因为您正在解析JSON)


如果你不能手工制作一个包含你试图保存的内容的plist,那么数组也不能写入它。

为什么你要写两次相同的数组?并检查你的可变数组是否为零。哇!我现在有点尴尬…它确实为零。谢谢Max!:)不,这是一个简单得多的问题:我的数组为零:/抱歉浪费了您的时间!啊哈。不用担心,有一天当别人有一个数组没有写入磁盘时,我的答案可能会帮助他们。。。