This function worked before the curse of all curses, also known as Swift 3. After migrating to Swift 3, Xcode, my friendly and cuddly IDE, displays this frustrating error against the line SCNTransaction.completionBlock
:
这个功能在所有诅咒的诅咒前起作用,也被称为Swift 3。在迁移到Swift 3之后,我友好而可爱的IDE Xcode对scntransactionaction显示了这个令人沮丧的错误。
Cannot call value of non-function type '(() -> Void)?'
不能调用非函数类型的值'()-> Void)?
Several other posts deal with similar errors, but none of those solutions apply.
其他几个帖子也处理类似的错误,但没有一个解决方案适用。
What is wrong with the line???
这条线怎么了?
func test(_ block: SCNNode, animated: Bool) {
// Do stuff
SCNTransaction.begin()
SCNTransaction.animationDuration = animated ? AnimationDur : 0.0
SCNTransaction.completionBlock {
block.removeFromParentNode()
}
// Animate stuff
SCNTransaction.commit()
}
2 个解决方案
#1
12
SCNTransaction.completionBlock is a class property. Perhaps you mean this?
completionblock是一个类属性。也许你的意思是这个吗?
// ↓
SCNTransaction.completionBlock = {
block.removeFromParentNode()
}
#2
3
SCNTransaction.completionBlock
isn't a function you can call via trailing closure syntax, it's a property. You'll need to assign the closure to it:
completionblock不是一个可以通过尾闭包语法调用的函数,而是一个属性。您需要将闭包分配给它:
SCNTransaction.completionBlock = {
block.removeFromParentNode()
}
In other words, you just need to add an equal sign.
换句话说,你只需要加上一个等号。
#1
12
SCNTransaction.completionBlock is a class property. Perhaps you mean this?
completionblock是一个类属性。也许你的意思是这个吗?
// ↓
SCNTransaction.completionBlock = {
block.removeFromParentNode()
}
#2
3
SCNTransaction.completionBlock
isn't a function you can call via trailing closure syntax, it's a property. You'll need to assign the closure to it:
completionblock不是一个可以通过尾闭包语法调用的函数,而是一个属性。您需要将闭包分配给它:
SCNTransaction.completionBlock = {
block.removeFromParentNode()
}
In other words, you just need to add an equal sign.
换句话说,你只需要加上一个等号。