Crashalot Crashalot - 2 months ago 35
Swift Question

Swift 3: Cannot call value of non-function type '(() -> Void)?'

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
:


Cannot call value of non-function type '(() -> 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()
}

Answer

SCNTransaction.completionBlock is a class property. Perhaps you mean this?

//                             ↓
SCNTransaction.completionBlock = {
    block.removeFromParentNode()
}
Comments