swift - Call a function which expects arguments with SKAction.runBlock() -
i'm working swift , spritekit
i'd use skaction.runblock() run function expect arguments :
class tile : skshapenode { } override func didmovetoview() { let tile = tile() tile.runaction(skaction.runblock(myfunc(tile))) } func myfunc(tile: tile) { }
when try create function doesn't expect argument, works fine, code above returns this:
cannot convert value of type '()' expected argument type 'dispatch_block_t' (aka '@convention(block) () -> ()')
what not understanding ?
with writing sort of expression:
skaction.runblock(myfunc(tile))
you passing result of calling myfunc(tile)
.
(i believe not think code: skaction.runblock(sin(0))
, pass sort of closure runblock
.)
and returned value myfunc(tile)
void value, myfunc
declared return nothing. void value can represented ()
. error message says ()
cannot converted closure of type @convention(block) () -> ()
.
thus, need create closure of type @convention(block) () -> ()
.
tile.runaction(skaction.runblock({()->() in myfunc(tile)}))
in short:
tile.runaction(skaction.runblock({myfunc(tile)}))
Comments
Post a Comment