Files
data-raft/Sources/DataRaft/Extensions/Notification+UserInfoKey.swift
2025-11-09 15:58:05 +02:00

34 lines
1.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
extension Notification {
/// A strongly typed key used to access values in a notifications user info dictionary.
///
/// ## Overview
///
/// `UserInfoKey` provides type safety when working with `Notification.userInfo`, replacing raw
/// string literals with well-defined constants. This helps prevent typos and improves
/// discoverability in database- or system-related notifications.
///
/// ## Topics
///
/// ### Keys
///
/// - ``action``
public struct UserInfoKey: RawRepresentable, Hashable, Sendable {
/// The raw string value of the key.
public let rawValue: String
/// The key used to store the action associated with a notification.
public static let action = Self(rawValue: "action")
/// Creates a user info key from the provided raw string value.
///
/// Returns `nil` if the raw value is invalid.
///
/// - Parameter rawValue: The raw string value of the key.
public init?(rawValue: String) {
self.rawValue = rawValue
}
}
}