gpt4 book ai didi

ios - NSCoding 编码对象数组

转载 作者:行者123 更新时间:2023-12-01 15:59:57 25 4
gpt4 key购买 nike

我需要对包含多个自定义 NSObject 实例的数组进行编码类(class)。但是,这样做时,它会返回带有消息的崩溃:

-[Person encodeWithCoder:]: unrecognized selector sent to instance 0x8ff2c50



该类包含多个属性并将它们存储为一个集合是该类的目的。

它崩溃的编码器方法是这样的:
- (void)encodeWithCoder:(NSCoder *)encoder 
{
[encoder encodeObject:_arrayOfPeople forKey:@"DataStoragePeopleArray"];
}

最佳答案

您需要执行 NSCoding Person 中的协议(protocol)类(class)。您希望编码的任何自定义类,包括当它包含在您正在编码的集合中时,都需要实现 NSCoding .

您需要实现 encodeWithCoder:initWithCoder: .

这是 NSCoding 的文档协议(protocol):

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSCoding_Protocol/Reference/Reference.html

关于ios - NSCoding 编码对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25684557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com