56 lines
1.5 KiB
Swift
56 lines
1.5 KiB
Swift
import Foundation
|
|
|
|
/// A transient in-app notification, posted and dismissed by a ``Notifier``.
|
|
public struct AppNotification: Equatable, Identifiable, Sendable {
|
|
|
|
// MARK: Properties
|
|
|
|
/// The unique identifier of the notification.
|
|
public let id: UUID
|
|
|
|
/// The kind of the notification, driving its visual weight.
|
|
public let kind: Kind
|
|
|
|
/// The localized message of the notification.
|
|
public let message: String
|
|
|
|
/// The system symbol of the notification's icon.
|
|
public let symbol: String
|
|
|
|
// MARK: Initializers
|
|
|
|
/// Creates a notification of a given kind, with a localized message and a system symbol.
|
|
///
|
|
/// - Parameters:
|
|
/// - id: The unique identifier of the notification. Defaults to a newly generated identifier.
|
|
/// - kind: The kind of the notification.
|
|
/// - message: The localized message of the notification.
|
|
/// - symbol: The system symbol of the notification's icon.
|
|
public init(
|
|
id: UUID = .init(),
|
|
kind: Kind,
|
|
message: String,
|
|
symbol: String
|
|
) {
|
|
self.id = id
|
|
self.kind = kind
|
|
self.message = message
|
|
self.symbol = symbol
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Enumerations
|
|
|
|
extension AppNotification {
|
|
/// The kind of a notification, driving its visual weight.
|
|
public enum Kind: Sendable {
|
|
/// The notification reports an error.
|
|
case error
|
|
/// The notification reports an informational event.
|
|
case info
|
|
/// The notification reports a warning.
|
|
case warning
|
|
}
|
|
}
|