MHMessageKit to your Swift Package Dependencies.
github "KoCMoHaBTa/MHMessageKit" to your
Cartfile, then Embed the framework directly into your project.
pod 'MHMessageKit' to your
You can use any of the above features independantly.
NotificationMessage protocol in conjuction with extensions to
NotificationQueue will allow you send and receive custom strongly typed notifications.
NotificationCenter- subscribe for receiving your custom messages
NotificationCenter- post instances of your custom messages
NotificationQueue- enque instances of your custom messages
You know, you have to laways unsubscribe observers when you no logner need them, usually in dealloc.
And it is even more uncovenient when you use the block based API from
NotificationCenter - you have to store the observer reference and again unsubscribe it when your class will get deallocated.
Well, in order to save tons of boilerplate code - we introduce the weak observers. Basically you use the same API, but your observer gets unsibscibed automatically upon dealloc. This means that you don't have to care anymore about unsibscibing - just subscribe and thats it.
In order to take advantage of this feature - just use the methods added to
addWeakObserver(forName:object:queue:using:) -> NSObjectProtocol
addWeakObserver(forObject:queue:handler:) -> NSObjectProtocol
subscribe(_:) -> WeakMessageSubscription
In case you want to have an independant messaging abstraction - there is one for you if think that it suits you.
It is defined as following:
Message- a type that can be send and received trough publishers and subscibers
MessagePublisher- a type that can send messages
MessageSubscriber- a type that manage message subscriptions
MessageSubscription- a type that represents a message subscription
WeakMessageSubscription- a type that represents a weak message subscription
StaticMessageHandler- a type that statically register and unregister subscriptions
StaticSubscriptionContainer- a type that stores subscriptions statically
StaticWeakSubscriptionContainer- a type that stores weak subscriptions statically
A default implementation using the Foundation's notification API is provided as following:
This means that in order to use this infrastructur - you have to:
In advance you could: