Skip to content

Instantly share code, notes, and snippets.

@kazukitanaka0611
Created January 15, 2016 03:53
Show Gist options
  • Save kazukitanaka0611/ac638b968aa6b16ddf34 to your computer and use it in GitHub Desktop.
Save kazukitanaka0611/ac638b968aa6b16ddf34 to your computer and use it in GitHub Desktop.
Swift、クロージャ、循環参照するパターン
class MyClass {
var total: Int = 0
lazy var myFunc: (x: Int, y: Int) -> Void = {(x: Int, y: Int) in
self.total = x + y
}
deinit {
print("deinit")
}
}
循環参照しないように
class MyClass {
var total: Int = 0
lazy var myFunc: (x: Int, y: Int) -> Void = {[unowned self] (x: Int, y: Int) in
self.total = x + y
}
deinit {
print("deinit")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment