How to save archive data to plist

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

  1. macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    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?
    Code:
    #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. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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. thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan

Share This Page