我想寫一個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");
我使用introspection來確保convertJSONtoDictionary實際上返回一個字典。
你爲什麼要寫同一個數組兩次?並檢查你的mutablearray是否不爲零。 – Max 2011-04-13 15:16:49
哇!我現在有些尷尬......確實沒有。謝謝Max! :) – Julian 2011-04-13 15:26:49