[writeTOFile: atomically:] not working

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

  1. sujithkrishnan macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #1
    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: ? ?

    Thanks
     
  2. kalimba macrumors regular

    Joined:
    Jun 10, 2008
    #2
    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

    Joined:
    Feb 2, 2010
    Location:
    Cali
    #3
    Any luck

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

    xsmasher

    Joined:
    Jul 18, 2008
    #4
    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:

    http://deadpanic.com/howtosave
     

Share This Page