Problem with writeToFile with array of NSDictionary objects
- by Ken
I'm trying to write an array of NSDictionary objects to a .plist file on the iPhone (OS 3.0). (They are actually NSCFDictionary objects when I call the [object class] method). My problem is that it won't write to file. If I set the array to "nil" it at least creates the empty plist file but won't do it if I have these objects in the array.
My array is a parsed response from a JSON HTTP request and looks like this:
{
"title" = "A Movie";
"time_length" = "3:22";
},
{
"title" = "Another Movie";
"time_length" = "1:40";
},
{
"title" = "A Third Movie";
"time_length" = "2:10";
}
The code to create the file is:
[array writeToFile:[self dataFilePath] atomically:YES];
- (NSString *)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@"data.plist"];
}
Could the NCSFDictionary class of the objects in my array be preventing me from writing to file? Thanks for your help.