5

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()
}
Crashalot
  • 33,605
  • 61
  • 269
  • 439

2 Answers2

18

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

//                             ↓
SCNTransaction.completionBlock = {
    block.removeFromParentNode()
}
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
4

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:

SCNTransaction.completionBlock = {
    block.removeFromParentNode()
}

In other words, you just need to add an equal sign.

Jack Lawrence
  • 10,664
  • 1
  • 47
  • 61