Last active
February 24, 2017 03:21
-
-
Save el-hoshino/3d8c6847862a043bbdd57d3c5c7724ff to your computer and use it in GitHub Desktop.
lazy var の遅延参照?という面白い動き ref: http://qiita.com/lovee/items/5f68762cb46c70af0c9a
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
struct Data { | |
var int = 1 | |
mutating func increase(completion: (Int) -> Void) { | |
self.int += 1 | |
completion(self.int) | |
} | |
} | |
class Manager { | |
var data = Data() | |
var int: Int { | |
return self.data.int | |
} | |
func increase() { | |
self.data.increase { (i) in | |
print(i) | |
print(self.int) | |
} | |
} | |
} | |
let manager = Manager() | |
manager.increase() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment