closures - Completion Handlers in Swift -


i'm new @ swift development , trying handle on closures , completion handlers. have function following declaration inside struct called objectdata

func getdata(id1:int, id2:int, completion: (dataobject? -> void))  

i trying call function like

objectdata.getdata(1, id2: 2){     (let myobject) in } 

but following error

cannot invoke 'getdata' argument list of type '(nsnumber, id2: nsnumber, (_) -> _)'

please can help

for better readability, change header this. remember have declare types, not variable names:

func getdata(id1:int, id2:int, completion: (objectdata?) -> (void)) 

now use syntax use closures:

self.getdata(1, id2: 1) { (data) -> (void) in       // code executed in closure } 

if want study further, can find full syntax of closures here (notice appropriate name of website). hope helps!


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -