如何在Swift 4中遵循NSCopying和实现copyWithZone?

How to conform to NSCopying and implement copyWithZone in Swift 4?

当我尝试使用 swift 3 方式时,我无法遵守 NSCopying 协议, 我的代码是:

public func copy(with zone: NSZone? = nil) -> Any {
    return type(of:self).init(self)
}

但是出现错误: Cannot call value of non-function type 'ProductType'

这里有什么问题?

我刚刚找到解决方案,更改功能为:

public func copy(with zone: NSZone? = nil) -> Any {
     return Swift.type(of:self).init(self)
 }