How to implement NSCoding on a generic class in Swift?

懵懂的女人 提交于 2019-12-03 10:27:26

The moment you make the class generic, it becomes non-compatible with Objective-C. The NSCoder stuff all happens in Objective-C which can no longer access your class.

Note there are other consequences of making the class generic as well. For example, if you were to add a description property, you'll also get a compile-time error:

// Error: '@objc' getter for non-'@objc' property
override var description: String {
    return "Foo: \(bar)"
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!