[writeTOFile: atomically:] not working

Discussion in 'iOS Programming' started by sujithkrishnan, Mar 26, 2009.

  1. sujithkrishnan macrumors 6502

    May 9, 2008
    Hi all,

    I am working out with teh method writeToFile: atomically: with the NSArray and NSDictionary.

    However i tried adding some simple strings to dictionary as key and values.
    The dictionary got saved successfully.

    However i added some custom object (say itemObject of type Item) to dictionary with some unique NSString as key.

    But writeToFile: is returning me NO

    The Item class implemented encodeWithCoder and decodeWithCoder methods to encode/decode the properties.

    I can succesfully persist the same Object using NSKeyedArchiver.

    Why its not working with writeToFile: ? ?

  2. kalimba macrumors regular

    Jun 10, 2008
    Have you checked the Apple documents for the NSArray and/or NSDictionary class reference?

    "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."
  3. jlobe macrumors newbie

    Feb 2, 2010
    Any luck

    I'm having a similar problem, did you ever sort this out?
  4. xsmasher macrumors regular


    Jul 18, 2008
    Kalimba already had the answer - you can only save specific types with this method. Either have your object create a dictionary of those types for saving / loading, or better yet use NSCoding:


Share This Page