欢迎访问Ningto's博客

Menu
  • 首页
  • 归档
  • 关于
  • 书签
  • 必应壁纸
  • IT聚合
  • 工具
    • 我的工具列表
    • 我的网盘
    • 必应每日壁纸API
    • Html转Markdown
    • 仙尘光标
Menu

swift delegate

最后更新 2017-06-10 11:53:47   阅读量 2585
protocol ModelDelegate {
    func willValueChanged(curValue: Int, newValue: Int)
    func didValueChanged(curValue: Int, oldValue: Int)
}

class Model {
    var delegate: ModelDelegate?
    
    var count: Int = 0 {
        willSet {
            delegate?.willValueChanged(count, newValue: newValue)
        }
        didSet {
            delegate?.didValueChanged(count, oldValue: oldValue)
        }
    }
}

class View: ModelDelegate {
    func willValueChanged(curValue: Int, newValue: Int) {
        print("will, cur:\(curValue), new:\(newValue)")
    }
    
    func didValueChanged(curValue: Int, oldValue: Int) {
        print("did, cur:\(curValue), old:\(oldValue)")
    }
}

let model = Model()
let view = View()
model.delegate = view
model.count = 100
model.count = 200

(转载本站文章请注明作者和出处:泞途 - ningto.com)

下一篇 – 给UITableView增加拷贝
上一篇 – App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.

  1. Mobile

toningto@outlook.com

推荐文章

Effective Python

Python的几种函数参数类型

标签云

Mac React Database Qt Node.js Javascript Product C/C++ Python Bug Tools Windows Linux Tips Design Go IOS MongoDB Shell Android Mobile Life Java Web MQ Others Boost

推广链接

【腾讯云】云产品限时秒杀,爆款1核2G云服务器,首年99元

多谢支持,用了好几年,服务很稳定支持多设备!

其他

文章RSS

Copyright © 2016 Welcome To Ningto Blog | 鄂ICP备17003086号-2