How to restore an array with NSCoder
-
03-10-2019 - |
Question
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?
Solution
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"];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow