This is a nice solution for Swift 2.x (update to Swift 3.x here below..) created by Daniel L. Alves, using SKNode
extension:
extension SKNode
{
func runAction( action: SKAction!, withKey: String!, optionalCompletion: dispatch_block_t? )
{
if let completion = optionalCompletion
{
let completionAction = SKAction.runBlock( completion )
let compositeAction = SKAction.sequence([ action, completionAction ])
runAction( compositeAction, withKey: withKey )
}
else
{
runAction( action, withKey: withKey )
}
}
}
Update to Swift 3.x
extension SKNode
{
func run(action: SKAction!, withKey: String!, optionalCompletion:((Void) -> Void)?) {
if let completion = optionalCompletion
{
let completionAction = SKAction.run(completion)
let compositeAction = SKAction.sequence([ action, completionAction ])
run(compositeAction, withKey: withKey )
}
else
{
run( action, withKey: withKey )
}
}
func actionForKeyIsRunning(key: String) -> Bool {
return self.action(forKey: key) != nil ? true : false
}
}