Skip to content

Instantly share code, notes, and snippets.

@goodmorningcody
Last active April 24, 2016 05:20
Show Gist options
  • Save goodmorningcody/70a17253fed919e887cec224980de6e1 to your computer and use it in GitHub Desktop.
Save goodmorningcody/70a17253fed919e887cec224980de6e1 to your computer and use it in GitHub Desktop.
스위프트 : 중첩함수를 사용한 캡쳐링
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