How to save archive data to plist

Discussion in 'iOS Programming' started by mikezang, Aug 11, 2010.

  1. mikezang macrumors 6502a

    May 22, 2010
    Tokyo, Japan
    I am reading "Beginning iPhone 3 Development", there is a sample to read archive data in plist as below but no code for save data. I want to save data back to plist after I modified data in self.list, what can I do?
    #import "PresidentsViewController.h"
    #import "PresidentDetailController.h"
    #import "President.h"
    @implementation PresidentsViewController
    @synthesize list; - (void)viewDidLoad {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Presidents"*ofType:@"plist"];
        NSData *data;
        NSKeyedUnarchiver *unarchiver;
        data = [[NSData alloc] initWithContentsOfFile:path];
        unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
        NSMutableArray *array = [unarchiver decodeObjectForKey:@"Presidents"];
        self.list = array;
        [unarchiver finishDecoding];
        [unarchiver release];
        [data release];
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    Read the Archives and Serialization documentation and learn how to do the reverse of the above.

    I'm not about to post the code for you: you'll learn nothing from simply copying others code and thinking you now know how to write it. The only way to learn is to write the code yourself, make mistakes, learn how to debug and then learn from those mistakes.
  3. mikezang thread starter macrumors 6502a

    May 22, 2010
    Tokyo, Japan

Share This Page