[iPhone]Objective C,不符合 NSCoding 的对象。如何将它们写入文件
我正在使用 Objective c 类,它是 NSObject 的子类。 无法修改该类。我有一个此类的实例,我希望将其写入一个可以检索并稍后恢复的文件。该对象不符合 NSCoding。
总而言之,我需要将类的实例保存到稍后可以检索的文件中,而不使用任何 NSCoding 方法,例如 NSKeyedArchivingencodeWithCoder ...
使用它们返回这个... NSInvalidArgumentException ...encodeWithCoder:] 无法识别的选择器发送到实例...
是否有其他方法可以存储此对象以供以后使用 谢谢
p.s 该类是一个 UIEvent
I am using an Objective c class, a subclass of NSObject.
This class cannot be modified. I have an instance of this class that I wish to write to a file which can be retrieved and later reinstate. The object does not conform to NSCoding.
To sum up, I need to save an instance of a class to a file which can be retrieved later, without using any of the NSCoding methods such as NSKeyedArchiving encodeWithCoder ...
Using them returns this...
NSInvalidArgumentException ...encodeWithCoder:]
unrecognised selector sent to instance...
Is there any other way I can store this object for later use
Thank you
p.s The class is a UIEvent
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能子类化该类并在子类中实现 NSCoding 协议吗?
Can you subclass the class and implement the NSCoding protocol in the subclass?
根据对象的成员内容,您可以创建一个字典,并将每个成员的值设置为字典中的键,然后将其写入文件。
但是,我不明白为什么你不能像 Jaanus 建议的那样子类化对象并实现 NSCoding 协议?
Depending on what the object has as members, you could create a dictionary, and set each member's value as a key in the dictionary and then write that to file.
However, I don't understand why you can't subclass the object and implement the NSCoding protocol, as Jaanus suggested?