嘿,自从我搬到Swift 3后,我得到了这个错误,说我的SCNTransaction
扩展名中的completionBlock是一个常量,我不确定如何将它更改为“var”任何帮助?
代码:
extension SCNTransaction {
class func animateWithDuration(_ duration: CFTimeInterval = 0.25, timingFunction: CAMediaTimingFunction? = nil, completionBlock: (() -> Void)? = nil, animations: () -> Void) {
begin()
animationDuration = duration
completionBlock = completionBlock
animationTimingFunction = timingFunction
animations()
commit()
}
}
答案 0 :(得分:3)
我认为这个问题与类completionBlock
的实例变量SCNTransaction
与函数的参数completionBlock
共享的事实有关。因此,代码行completionBlock = completionBlock
被解释为对参数completionBlock
的值的赋值,而不是同名的实例变量。这是无效的,因为默认情况下函数参数是常量,用let
声明。您需要做的就是消除您所指的completionBlock
的歧义:
class func animateWithDuration(... completionBlock: (() -> Void)? = nil, ... ) {
...
self.completionBlock = completionBlock
...
}