|
8 | 8 | import UIKit |
9 | 9 |
|
10 | 10 | /// Represents the enum containing all the quick action types available for your application. |
| 11 | +/// A marker protocol that identifies a type-safe identifier for Home Screen quick actions. |
| 12 | +/// |
| 13 | +/// Conform your enumeration to `QuickActionType` to declare the complete, strongly-typed |
| 14 | +/// set of quick actions your app supports. The protocol refines several standard Swift |
| 15 | +/// protocols to ensure identifiers are safe to use across threads, easy to store, and |
| 16 | +/// stable to serialize: |
| 17 | +/// - `RawRepresentable` with `RawValue == String`: Each case must map to a unique string |
| 18 | +/// value, which is used by the system (e.g., `UIApplicationShortcutItem.type`) and for |
| 19 | +/// persistence or deep linking. |
| 20 | +/// - `Hashable`: Enables use in sets, dictionaries, and as stable identifiers. |
| 21 | +/// - `Sendable`: Ensures values can safely cross concurrency boundaries. |
| 22 | +/// |
| 23 | +/// Typical usage: |
| 24 | +/// ```swift |
| 25 | +/// enum AppQuickAction: String, QuickActionType { |
| 26 | +/// case note, search, favorites |
| 27 | +/// } |
| 28 | +/// ``` |
| 29 | +/// |
| 30 | +/// See also: |
| 31 | +/// - ``QuickActionsItem`` for modeling a full quick action entry presented to the user. |
11 | 32 | public protocol QuickActionType: Sendable, RawRepresentable, Hashable where RawValue == String {} |
12 | 33 |
|
13 | 34 | /// Represents a quick action item shown in the menu. |
| 35 | +/// A value type that models a single Home Screen quick action entry for your app. |
| 36 | +/// |
| 37 | +/// Use `QuickActionsItem` to describe the content and behavior of a quick action that |
| 38 | +/// appears in the system-provided menu (for example, via Home Screen icon context menu). |
| 39 | +/// Each item carries a strongly-typed identifier (`type`), user-visible strings (`title` |
| 40 | +/// and optional `subtitle`), an optional icon, and a Boolean that indicates whether the |
| 41 | +/// action is currently available. |
| 42 | +/// |
| 43 | +/// - Generic Parameter: |
| 44 | +/// - T: A concrete type conforming to ``QuickActionType`` that uniquely identifies |
| 45 | +/// the action. This enables type-safe handling and pattern matching of actions. |
| 46 | +/// |
| 47 | +/// The struct conforms to `Hashable`. Two `QuickActionsItem` values are considered equal |
| 48 | +/// if, and only if, their `type` values are equal. This makes `type` the logical unique |
| 49 | +/// identifier for items, which is useful when storing items in sets or using them as |
| 50 | +/// dictionary keys. |
| 51 | +/// |
| 52 | +/// Typical usage includes: |
| 53 | +/// - Defining an enum that conforms to ``QuickActionType`` to enumerate all actions. |
| 54 | +/// - Creating one `QuickActionsItem` per action with localized titles, optional subtitles, |
| 55 | +/// and an appropriate icon. |
| 56 | +/// - Toggling `availability` to dynamically include or exclude an action from the menu. |
| 57 | +/// |
| 58 | +/// Example: |
| 59 | +/// ```swift |
| 60 | +/// enum AppQuickAction: String, QuickActionType { |
| 61 | +/// case note, search, favorites |
| 62 | +/// } |
| 63 | +/// |
| 64 | +/// let item = QuickActionsItem<AppQuickAction>( |
| 65 | +/// type: .note, |
| 66 | +/// title: "New Note", |
| 67 | +/// subtitle: "Create a blank note", |
| 68 | +/// icon: .systemName("square.and.pencil"), |
| 69 | +/// availability: true |
| 70 | +/// ) |
| 71 | +/// ``` |
| 72 | +/// |
| 73 | +/// - Note: The `icon` supports multiple representations, including system icon names and |
| 74 | +/// `UIApplicationShortcutIcon.IconType`, to integrate with the system quick action UI. |
| 75 | +/// |
| 76 | +/// - SeeAlso: ``QuickActionType`` and ``QuickActionsItem/Icon`` |
14 | 77 | public struct QuickActionsItem<T>: Hashable where T: QuickActionType { |
15 | 78 | // MARK: Properties |
16 | 79 | /// The unique quick action type. |
@@ -51,6 +114,25 @@ public struct QuickActionsItem<T>: Hashable where T: QuickActionType { |
51 | 114 |
|
52 | 115 | extension QuickActionsItem { |
53 | 116 | // MARK: Data |
| 117 | + /// Represents the visual symbol displayed alongside a quick action in the system menu. |
| 118 | + /// |
| 119 | + /// Use `Icon` to describe how the quick action should appear visually. The enum supports |
| 120 | + /// multiple representations to align with system-provided icons and custom assets. |
| 121 | + /// |
| 122 | + /// Cases: |
| 123 | + /// - `type(UIApplicationShortcutIcon.IconType)`: Uses a predefined system shortcut icon |
| 124 | + /// provided by UIKit. This is the most native option and ensures visual consistency |
| 125 | + /// with system quick actions. |
| 126 | + /// - `systemName(String)`: Uses an SF Symbols system image by name (e.g., "square.and.pencil"). |
| 127 | + /// Prefer this when you want a modern, scalable symbol that follows system design. |
| 128 | + /// - `template(String)`: Uses the name of a templated image asset in your app bundle. |
| 129 | + /// The image should be a monochrome, template-rendered asset suitable for tinting. |
| 130 | + /// |
| 131 | + /// Notes: |
| 132 | + /// - Not all SF Symbols are available on all platform versions. Ensure compatibility for |
| 133 | + /// targeted iOS, iPadOS, or other Apple platforms. |
| 134 | + /// - Template images should be provided as single-color assets intended for tinting. |
| 135 | + /// - The exact rendering of the icon may vary based on the system UI and context. |
54 | 136 | public enum Icon: Hashable { |
55 | 137 | case type(UIApplicationShortcutIcon.IconType) |
56 | 138 | case systemName(String) |
|
0 commit comments