What is the way to save objects? (so far only used plist)

Discussion in 'iOS Programming' started by yalag, Aug 14, 2008.

  1. yalag macrumors 65816

    Joined:
    Nov 18, 2007
    #1
    So far all the persistence data for my app has been done with plist which accepts id of a basic type (NSNumber, NSDate etc). What is the best way to save a NSArray of Object, of which the object has members of a lot of data? Do I have to save each member manually or is there a neat way of saving objects?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  3. yalag thread starter macrumors 65816

    Joined:
    Nov 18, 2007
    #3
    When should you be using NSCoder, when plist?
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    You can use NSKeyedArchiver and NSKeyedUnarchiver to save/load an object that conforms to the NSCoding protocol into an NSData object, which can then be inserted into a property list.
     
  5. yalag thread starter macrumors 65816

    Joined:
    Nov 18, 2007
    #5
    ah thank you. so just have to use plist either way for iphone data? Or can you just use the archiver to save to disk directly?
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    You can save an NSData object using writeToFile:atomically:
     

Share This Page