Avatar
omochimetaru 10/1/2018 3:57 PM
@swift-4.2.4 class Cat { init() { print("init cat") } deinit { print("deinit cat") } func nya() -> () -> Void { print("begin nya") weak var wself = self var stone = Int(2) { didSet { guard let self = wself else { return } print(self) } } print("end nya") return { print(stone) } } } func main() { var cap: (() -> Void)? = nil do { print("---1---") let cat = Cat() print("---2---") cap = cat.nya() } // end of `cat` print("---3---") cap = nil print("---4---") } main()