class Obserber { var name:String? var count:Int = 0 { willSet{ print("Will set an new value \(newValue) to count,current count is \(count)") } dIDSet{ print("count changed form \(oldValue) to \(count)") if count < 10 { name = "name1" }else { name = "name2" } } }}var ob:Obserber = Obserber()ob.count = 15
输出结果为:
Will set an new value 15 to count,current count is 0
count changed form 0 to 15
总结以上是内存溢出为你收集整理的Swift中观察者模式观察一个值的变化全部内容,希望文章能够帮你解决Swift中观察者模式观察一个值的变化所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)