I'm trying to write an NSMutableArray to a file, however it fails every single time. I believe that the path I have stated is correct. What else could be the problem?
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 = NSSearchPathForDirectoriesInDoma开发者_StackOverflow中文版ins(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");
I'm using introspection to ensure that convertJSONtoDictionary actually returns a dictionary.
You probably have some kind of object in the array that it cannot write out into a plist (which is by default the storage mechanism for an array).
Common examples would be any custom class, a UIImage, or NSNull (since you have JSON you are parsing).
If you cannot make a plist by hand that has what you are trying to save out then the array cannot write it either.
精彩评论