ios - Swift Closure why does calling function return error? -


just learning closures , nesting functions. given nested function below:

func printerfunction() -> (int) -> () {     var runningtotal = 0     func printinteger(number: int) {         runningtotal += 10         println("the running total is: \(runningtotal)")     }     return printinteger } 

why calling func have error, when assign func constant have no error? printandreturnintegerfunc(2) passing 2 int parameter have return value?

printerfunction(2) // error let printandreturnintegerfunc = printerfunction()  printandreturnintegerfunc(2) // no error. 2 going?? 

first of getting error here printerfunction(2) because printerfunction can not take argument , if want give argument can like:

func printerfunction(abc: int) -> (int) -> (){   } 

and work fine:

printerfunction(2) 

after giving reference of function variable this:

let printandreturnintegerfunc = printerfunction()  

which means type of printandreturnintegerfunc this:

enter image description here

that means accept 1 int , return void work:

printandreturnintegerfunc(2) 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -