类的实例被销毁时会立刻执行析构器
//析构器
class Point{
let x: Int
let y: Int
init(x: Int, y: Int){
self.x = x
self.y = y
}
deinit {
print("Point is clenaed up.")
}
}
var p1: Point? = Point(x: 1, y: 1)
p1 = nil //析构器将被调用
网友评论