代码之家  ›  专栏  ›  技术社区  ›  DariusV

如何符合NSCopying并在Swift 4中实施copyWithZone?

  •  4
  • DariusV  · 技术社区  · 9 年前

    当我尝试使用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'

    这里有什么问题?

    1 回复  |  直到 9 年前
        1
  •  3
  •   DariusV    9 年前

    我刚刚找到了解决方案,将函数更改为:

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