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:

that means accept 1 int , return void work:
printandreturnintegerfunc(2) 
Comments
Post a Comment