Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
939
41
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?
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];
 }
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.