Problem with writeToFile with array of NSDictionary objects
Posted
by Ken
on Stack Overflow
See other posts from Stack Overflow
or by Ken
Published on 2009-12-08T02:59:09Z
Indexed on
2010/03/12
5:07 UTC
Read the original article
Hit count: 312
iphone
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.
© Stack Overflow or respective owner