奈多罗米钠,天天向上20100416,n0475
与构造过程相反,实例最后释放的时候,需要清除一些资源,这个过程就是析构过程。在析构过程中也会调用一种特殊的方法deinit,称为析构函数。析构函数deinit没有返回值,也没有参数,也不需要参数的小括号,所以不能重载。class rectangle { var width: double var height: double init(width: double, height: double){ self.width = width self.height = height } init(w width: double,h height: double){ self.width = width self.height = height } deinit { //定义了析构函数 print("调用析构函数...") self.width = 0.0 self.height = 0.0 } } var rectc1: rectangle? = rectangle(width: 320, height: 480) //实例rectc1 print("长方形:\(rectc1!.width) x\(rectc1!.height)") rectc1 = nil //触发调用析构函数的条件 var rectc2: rectangle? = rectangle(w: 320, h: 480) //实例rectc2 print("长方形:\(rectc2!.width) x\(rectc2!.height)") rectc2 = nil //触发调用析构函数的条件
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
iOS 使用UITextField自定义搜索框 实现用户输入完之后“实时搜索”功能
网友评论