Swift NSKeyedArchiver:符合 NSCoding 的自定义成员 class 是否也需要符合 NSCoding?
Swift NSKeyedArchiver: Do custom members of an NSCoding-conformant class need to conform to NSCoding as well?
说我有这个 Swift class:
class Foo: NSObject, NSCoding
{
var stringMember: String
var intMember: Int
var customObjectMember: CustomObject
//conforms with encode and required init...
}
我知道 "Foo" 必须符合 NSCoding,所以我可以存档它。成员 "customObject" 是否也必须符合 NSCoding/NSObject 还是可以是常规 Swift class?
答案是"yes"。自定义对象成员也必须符合 NSCoding。
说我有这个 Swift class:
class Foo: NSObject, NSCoding
{
var stringMember: String
var intMember: Int
var customObjectMember: CustomObject
//conforms with encode and required init...
}
我知道 "Foo" 必须符合 NSCoding,所以我可以存档它。成员 "customObject" 是否也必须符合 NSCoding/NSObject 还是可以是常规 Swift class?
答案是"yes"。自定义对象成员也必须符合 NSCoding。