/SwiftObserverCenter

Primary LanguageSwiftMIT LicenseMIT

SwiftObserverCenter

CI Status Version License Platform

SwiftObserverCenter is a notification centers built based on protocol, which provides better use experience than the Apple Native NSNotificationCenter.

Example

Defind Topic and method

Because of Generics AnyObject, protocol must use @objc now,If you have a better way, please let me know.

@objc protocol Topic {
    func receiveMsg(msg: String,from: String)
}

Add Observer

AddObserver(topic: Topic.self, observer: self);

Publish Observer

PublishObserver(topic: Topic.self) { topic in
    topic.receiveMsg(msg: "你今天摸鱼了吗?", from: "张三")
}

Remove Observer

RemoveObserver(topic: Topic.self, observer: self)

Installation

To install it, simply add the following line to your Podfile:

pod "SwiftObserverCenter"

Author

corotata, corotata@qq.com

License

SwiftObserverCenter is available under the MIT license. See the LICENSE file for more info.