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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -