0

Hi i am trying to write an NSDictionary to a plist in the documents folder, but unable to write , i am using the writeToFile:atomically: method , which returns False. The complete code is

-(void)writeData:(NSDictionary *)dicResponseData
{
    // get paths from root directory

    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    // get documents path
    NSString *documentsPath = [paths objectAtIndex:0];
    // get the path to our Data/plist file
    NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Contractors.plist"];   

    [dicResponseData writeToFile:plistPath atomically: TRUE];  
}

the dictionary contains 25 sub dictionaries in it .

QED
  • 9,803
  • 7
  • 50
  • 87
Singh
  • 2,151
  • 3
  • 15
  • 30
  • 2
    You don't accept answers, so It's not very likely anyone is willing to even help you. – skram May 31 '12 at 14:09
  • 1
    @skram now i will accept answers , till now i did nt knew the process. – Singh May 31 '12 at 14:16
  • It happens - you're not the only one. I'm sure you'll get better responses from now on. :) – Rok Jarc May 31 '12 at 14:17
  • Try writing with `[dicResponseData writeToFile:plistPath options:NSDataWritingAtomic error:&error]` and check out the error message. – Alexander May 31 '12 at 14:20
  • @Alexander the method you specified i used to write NSData , but i need to write NSDictionary – Singh May 31 '12 at 14:22
  • Try converting it to NSData and saving it this way. One or more of your objects in your dictionaries might not be proper property list types. – Alexander May 31 '12 at 19:50

1 Answers1

1

All objects in your dictionary have to be property list objects.

This method recursively validates that all the contained objects are property list objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary) before writing out the file, and returns NO if all the objects are not property list objects, since the resultant file would not be a valid property list.

Jody Hagins
  • 27,943
  • 6
  • 58
  • 87