on the line "let runBlock = SCNAction.run { (node) -> Void in block(node) }" I'm getting "Escaping closure captures non-escaping parameter 'block' error", which seems to be caused by older syntax, wonder what should be the correct usage here
extension SCNAction {
class func waitForDurationThenRemoveFromParent(duration:TimeInterval) -> SCNAction {
let wait = SCNAction.wait(duration: duration)
let remove = SCNAction.removeFromParentNode()
return SCNAction.sequence([wait,remove])
}
class func waitForDurationThenRunBlock(duration:TimeInterval, block: ((SCNNode?) -> Void) ) -> SCNAction {
let wait = SCNAction.wait(duration: duration)
let runBlock = SCNAction.run { (node) -> Void in
block(node)
}
return SCNAction.sequence([wait,runBlock])
}
class func rotateByXForever(x:CGFloat, y:CGFloat, z:CGFloat, duration:TimeInterval) -> SCNAction {
let rotate = SCNAction.rotateBy(x: x, y: y, z: z, duration: duration)
return SCNAction.repeatForever(rotate)
}
}
CodePudding user response:
Make the block escaping
class func waitForDurationThenRunBlock(duration:TimeInterval, @escaping block: ((SCNNode?) -> Void) ) -> SCNAction {
let wait = SCNAction.wait(duration: duration)
let runBlock = SCNAction.run { (node) -> Void in
block(node)
}
return SCNAction.sequence([wait,runBlock])
}