Created
January 15, 2016 03:53
-
-
Save kazukitanaka0611/ac638b968aa6b16ddf34 to your computer and use it in GitHub Desktop.
Swift、クロージャ、循環参照するパターン
This file contains hidden or 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
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