Skip to content

Instantly share code, notes, and snippets.

@el-hoshino
Last active February 24, 2017 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save el-hoshino/3d8c6847862a043bbdd57d3c5c7724ff to your computer and use it in GitHub Desktop.
Save el-hoshino/3d8c6847862a043bbdd57d3c5c7724ff to your computer and use it in GitHub Desktop.
lazy var の遅延参照?という面白い動き ref: http://qiita.com/lovee/items/5f68762cb46c70af0c9a
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