编码器编码对象
考虑以下代码
[coder encodeObject: properties forKey:@"properties"];
作为参数传递给encodeObject 的对象类型是否有任何限制?它可以是自定义类中的对象吗?
Consider the following code
[coder encodeObject: properties forKey:@"properties"];
Are there any restrictions on what kind of object is passed as an argument to encodeObject? Can it be an object from a custom class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以对任何对象进行编码,只要它实现
NSCoding
协议(许多“默认”类 - 例如NSString
、NSArray
、>NSDictionary
、NSData
等 - 已经实现了此协议,并且您可以毫无问题地对它们进行编码)。如果要对自定义对象的数组或字典进行编码,这些对象也必须实现该协议。您可以在 档案和序列化编程指南 和 NSCoding 协议参考...
You can encode any object, as long as it implements the
NSCoding
protocol (many 'default' classes - such asNSString
,NSArray
,NSDictionary
,NSData
, etc. - already implement this protocol, and you can encode them without problem). If you want to encode an array or dictionary of custom objects, those objects will have to implement the protocol as well.You can read more about this in the Archives and Serializations Programming Guide and the NSCoding Protocol Reference...