-
Notifications
You must be signed in to change notification settings - Fork 2.9k
NotifableProtocol
roux g. buciu edited this page Feb 24, 2022
·
2 revisions
This is a simple protocol to make setting up basic notifications very easy.
It provides access to a notificationCenter
property. This should be initialized with a default of NotificationCenter.default
in the initializer, for testing purposes.
It also provides a simple interface for setting up notifications where the object is nil
and the observer is self
. Do this by calling setupNotifications(...)
wherever you would normally do so, and pass in self
and an array of Notification.Name
that you wish to observe.
The protocol will also ask you to conform to handleNotifications(...)
wherein you should do a basic switch
on the notification name and then take the appropriate action.