Last active
April 24, 2016 05:20
-
-
Save goodmorningcody/70a17253fed919e887cec224980de6e1 to your computer and use it in GitHub Desktop.
스위프트 : 중첩함수를 사용한 캡쳐링
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func makeAddingClosure(start:Int)->(Int)->(Int) { | |
var total = start | |
func add(num:Int)->Int { | |
total = total + num | |
return total | |
} | |
return add | |
} | |
let capturedNestFunction = makeAddingClosure(10) | |
capturedNestFunction(1) | |
capturedNestFunction(8) | |
capturedNestFunction(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment