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’s Notification type. All conforming types must specify the type of the object attached to the notification. Conforming types can attach additional data to the notification as properties. This replaces stringly typed userInfo dictionary attached to Foundation Notifications

    Conforming 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 static name property on your notification types:

    struct DataStoreDidSaveNotification: TypedNotification {
    
        static let name = Notification.Name("XYZDataStoreDidSave")
    
        /// The data store posting the notification.
        let object: DataStore
    }
    
    See more

    Declaration

    Swift

    public protocol TypedNotification