Swift3 中的 copyWithZone

copyWithZone in Swift3

我正在尝试将一个函数转换为较新的 Swift3 版本,但出现错误。该操作发生在 UICollectionViewLayoutAttributes class 中,称为 CircularCollectionViewLayoutAttributes 并且 class 开始如下:

class CircularCollectionViewLayoutAttributes: UICollectionViewLayoutAttributes { ...

功能代码:

override func copy(with zone: NSZone? = nil) -> Any {
let copiedAttributes: CircularCollectionViewLayoutAttributes = super.copy(zone) as! CircularCollectionViewLayoutAttributes
copiedAttributes.anchorPoint = self.anchorPoint
copiedAttributes.angle = self.angle
return copiedAttributes

}

差一点就改好了,但还是在线报错:

let copiedAttributes: CircularCollectionViewLayoutAttributes = super.copy(zone) as! CircularCollectionViewLayoutAttributes

表示:"Argument passed to call that takes no arguments" 并下划线 "zone"。

非常感谢您的帮助。

将 API 从 Objective-C 桥接到 Swift 时发生的变化之一是许多方法名称中的介词已变成参数标签。介词后的名词或动词的宾语通常被省略并用作内部参数名称。 copyWithZone就是其中之一。

这是Swift中的声明:

func copy(with zone: NSZone? = nil) -> Any

其他示例包括 prepare(for:) 来自 prepareForSeguepresent(_:animated:completion:) 来自 presentViewConroller 等。