Search code examples
swiftswift3scntranscaction

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()
}

Solution

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

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