前端之家收集整理的这篇文章主要介绍了
Swift基础篇——析构方法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
import Foundation
class FileHandler{
var fd: Int32?
init(path:String){
let ret = open(path,O_RDONLY)
if ret == -1{
fd = nil
}else{
fd = ret
}
print("对象被创建")
}
deinit{
if let ofd = fd{
close(ofd)
}
print("对象被销毁")
}
}
var fh:FileHandler? = FileHandler(path: "/Users/Jonathan_Lee/Desktop/老员工奖.xlsx")
fh = nil
class Person {
var name:String
init(name:String){
self.name = name
print("Person init")
}
deinit{
print("Person deinit")
}
}
class SuperMan: Person {
var age:Int
init(age:Int){
.age = age
super.init(name: "Swift")
print("SuperMan init")
}
deinit{
print("SuperMan deinit")
}
}
var sm: SuperMan? = SuperMan(age: 30)
sm = nil
原文链接:https://www.f2er.com/swift/325653.html