简体   繁体   中英

How to restore an array with NSCoder

So far I have the following:

- (id)initWithCoder:(NSCoder*) coder
{
    self = [super initWithCoder: coder];
    if (self) {
        // Call a setup method
    }
    return self;
}

Am I supposed to put the code to load the array in here? What could should I put and where should I put it?

You put myArray=[coder decodeObjectForKey:@"myArray"]; inside the if block.

If you haven't set up the encoding part of the code yet, to do that you just add a method:

- (void)encodeWithCoder:(NSCoder *)encoder {
    [encoder encodeObject:myArray forKey:@"myArray"];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM