Protocols
The following protocols are available globally.
-
A notification that can be posted by a
TypedNotificationCenter
instance.TypedNotification
provides a type-safe alternative to Foundation’sNotification
type. All conforming types must specify the type of theobject
attached to the notification. Conforming types can attach additional data to the notification as properties. This replaces stringly typeduserInfo
dictionary attached to FoundationNotification
sConforming to
TypedNotification
Conforming types must declare the type of the object attached to the notification and provide storage for it. For example, a notification posted by a
DataStore
object might look like this:struct DataStoreDidSaveNotification: TypedNotification { /// The data store posting the notification. let object: DataStore }
Customising the Notification Name
A default notification name for conforming types is generated in a protocol extension. The name consists of the name of the notification type prefixed by
AJJ
. You can specify a different name by implementing the staticname
property on your notification types:
See morestruct DataStoreDidSaveNotification: TypedNotification { static let name = Notification.Name("XYZDataStoreDidSave") /// The data store posting the notification. let object: DataStore }
Declaration
Swift
public protocol TypedNotification
-
A type that can post
See moreTypedNotification
s and add notification observers.Declaration
Swift
public protocol TypedNotificationCenter