测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | Apache 2 |
发布最后发布 | Sep 2016 |
SPM支持 SPM | ✗ |
由 Romain Francez 维护。
添加观察者并发送带优先级和类型值的通知。
BCNotificationCentre 通过 CocoaPods 提供使用。
pod 'BCNotificationCentre'
添加通知观察者
BCNotificationCentre.defaultCentre.addObserverForName("notificationName") { (notification: BCNotification<String>) -> Void in
// Do something with the notification
}
发布通知
let notification = BCNotification(name: "notificationName", value: "the value associated")
BCNotificationCentre.defaultCentre.postNotification(notification)
通知是分类型的
BCNotificationCentre.defaultCentre.addObserverForName("notificationName") { (notification: BCNotification<String>) -> Void in
// Do something with the notification with the associated string value
}
BCNotificationCentre.defaultCentre.addObserverForName("notificationName") { (notification: BCNotification<Int>) -> Void in
// Will not be called as the posted notification as an associated string value
}
let notification = BCNotification(name: "notificationName", value: "the value associated")
BCNotificationCentre.defaultCentre.postNotification(notification)
通知是优先级较高的
BCNotificationCentre.defaultCentre.addObserverForName("notificationName", priority: .Low) { (notification: BCNotification<String>) -> Void in
// This will be called after the normal priority notification
}
BCNotificationCentre.defaultCentre.addObserverForName("notificationName", priority: .Normal) { (notification: BCNotification<String>) -> Void in
// This will be called first
}
let notification = BCNotification(name: "notificationName", value: "the value associated")
BCNotificationCentre.defaultCentre.postNotification(notification)
BCNotificationCentre 可在 Apache License, Version 2.0 下使用。请参阅 LICENSE 文件获取更多信息。