99热99这里只有精品6国产,亚洲中文字幕在线天天更新,在线观看亚洲精品国产福利片 ,久久久久综合网

歡迎加入QQ討論群258996829

iOS通知中心封裝庫SwiftNotificationCenter

發(fā)布時間:2017-05-21 23:23  回復:0  查看:6923  感興趣:70  贊:2   最后回復:2017-05-21 23:23  
SwiftNotificationCenter是一個面向協(xié)議的iOS通知中心庫,用Swift編寫。
特性類型安全、線程安全、內存安全。
  • 類型安全
    沒有更多的userInfo字典和向下轉型,只要傳遞具體的值給觀察者。
  • 線程安全
    你可以在任何線程中register、notify、unregister,而不會崩潰和數(shù)據(jù)損壞。
  • 內存安全
    SwiftNotificationCenter將觀察者存儲為zeroing-weak引用。 沒有崩潰,無需手動注銷。
它簡單、安全、輕便、易于使用,用于一對多通信。
示例代碼:
//Define protocol and observer:
protocol Update {
    func updateTitle(title: String)
}

extension ViewController: Update {
  func updateTitle(title: String) {
  		self.titleLabel.text = title
  }
}
let vc = ViewController()


//Register:
Broadcaster.register(Update.self, observer: vc)


//Broadcast:
Broadcaster.notify(Update.self) {
    $0.updateTitle("new title")
}


//Unregister:
Broadcaster.unregister(Update.self, observer: self)


相關開源代碼

您還未登錄,請先登錄

熱門帖子

最新帖子

?