Skip to content

Instantly share code, notes, and snippets.

@aainaj
Created June 27, 2018 03:32
Show Gist options
  • Save aainaj/6c86edc7a297e8ed4de2f97b0870d825 to your computer and use it in GitHub Desktop.
Save aainaj/6c86edc7a297e8ed4de2f97b0870d825 to your computer and use it in GitHub Desktop.
Closure CaptureList
//: Playground - Closures
import Foundation
class CaptureList: NSObject {
let digit = 5
override init() {
super.init()
makeSquareOfValue { [digit] squareDigit in
print("Square of \(digit) is \(squareDigit)")
}
}
func makeSquareOfValue(onCompletion: (Int) -> Void) {
let squareDigit = digit * digit
onCompletion(squareDigit)
}
}
CaptureList()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment