[英]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"];
您将
myArray=[coder decodeObjectForKey:@"myArray"];
inside the if block. 在if块中。
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"];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.