简体   繁体   中英

Swift NSKeyedArchiver: Do custom members of an NSCoding-conformant class need to conform to NSCoding as well?

Say I have this Swift class:

class Foo: NSObject, NSCoding
{
    var stringMember: String
    var intMember: Int
    var customObjectMember: CustomObject
    //conforms with encode and required init...
}

I know that "Foo" has to conform to NSCoding so I can archive it. Does the member "customObject" also have to conform to NSCoding/NSObject or can it be a regular Swift class?

The answer is "yes". Custom object members must also conform to NSCoding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM