swift中提供属性监听器,可以监听属性的改变
发布时间:2020-12-14 07:02:13 所属栏目:百科 来源:网络整理
导读://:Playground-noun:aplacewherepeoplecanplayimportUIKitclassPerson:NSObject{//swift中提供属性监听器,可以监听属性的改变varname:String?{//在willSet方法中,系统提供一个标识符.//newValue:用于记录新传入的数据//自定义newValue和oldValue的名称//will
//:Playground-noun:aplacewherepeoplecanplay importUIKit classPerson:NSObject{ //swift中提供属性监听器,可以监听属性的改变 varname:String?{ //在willSet方法中,系统提供一个标识符. //newValue:用于记录新传入的数据 //自定义newValue和oldValue的名称 //willSet(new) willSet(new){ print(name) print(new) } //在didSet方法中,系统提供一个标识符. //oldValue:用户记录之前的值 //didSet(old) didSet(old){ print(name) print(old) } } varage:Int=0 } letp=Person() p.name="why" p.age=18 var imageList:Array<String>{ set{ _imageList = newValue; creatImageView(); } get{ return _imageList!; } //OC监听属性的改变:重写set方法 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |