From 6f1e491c567b27659a5b5c525b832b44a201094a Mon Sep 17 00:00:00 2001 From: Yazawa Hiroki <47569369+zunda-pixel@users.noreply.github.com> Date: Tue, 31 Mar 2026 11:15:03 +0900 Subject: [PATCH 1/2] add feedback generator api documents --- swiftui-expert-skill/SKILL.md | 2 ++ .../references/latest-apis.md | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/swiftui-expert-skill/SKILL.md b/swiftui-expert-skill/SKILL.md index f12241c..4647f46 100644 --- a/swiftui-expert-skill/SKILL.md +++ b/swiftui-expert-skill/SKILL.md @@ -9,6 +9,7 @@ description: Write, review, or improve SwiftUI code following best practices for - Consult `references/latest-apis.md` at the start of every task to avoid deprecated APIs - Prefer native SwiftUI APIs over UIKit/AppKit bridging unless bridging is necessary +- Prefer `sensoryFeedback()` over UIKit feedback generators when working in SwiftUI views - Focus on correctness and performance; do not enforce specific architectures (MVVM, VIPER, etc.) - Encourage separating business logic from views for testability without mandating how - Follow Apple's Human Interface Guidelines and API design patterns @@ -76,6 +77,7 @@ These are hard rules -- violations are always bugs: - [ ] `ForEach` uses stable identity (never `.indices` for dynamic content) - [ ] Constant number of views per `ForEach` element - [ ] `.animation(_:value:)` always includes the `value` parameter +- [ ] SwiftUI haptics use `sensoryFeedback()` instead of UIKit feedback generators - [ ] iOS 26+ APIs gated with `#available` and fallback provided - [ ] `import Charts` present in files using chart types diff --git a/swiftui-expert-skill/references/latest-apis.md b/swiftui-expert-skill/references/latest-apis.md index c193bfe..556c648 100644 --- a/swiftui-expert-skill/references/latest-apis.md +++ b/swiftui-expert-skill/references/latest-apis.md @@ -136,6 +136,29 @@ The deprecated variant passes only the new value. The modern variants provide ei - **With initial trigger**: `.onChange(of: value, initial: true) { ... }` - **Deprecated**: `.onChange(of: value) { newValue in ... }` — single-parameter closure +### Sensory Feedback + +**Prefer `sensoryFeedback(_:trigger:)` and related overloads instead of `UIImpactFeedbackGenerator`, `UISelectionFeedbackGenerator`, and `UINotificationFeedbackGenerator` in SwiftUI views.** + +Attach haptics declaratively to the view that owns the state change, rather than imperatively firing UIKit generators inside button actions. + +```swift +@State private var isFavorite = false + +Button("Favorite", systemImage: isFavorite ? "heart.fill" : "heart") { + isFavorite.toggle() +} +.sensoryFeedback(.selection, trigger: isFavorite) +``` + +Use the conditional overload when feedback should fire only for specific transitions: + +```swift +.sensoryFeedback(.selection, trigger: phase) { old, new in + old == .inactive || new == .expanded +} +``` + ### Gestures - **`MagnifyGesture`** instead of `MagnificationGesture` (access magnitude via `value.magnification`) @@ -454,6 +477,7 @@ PhotoGrid(photos: photos) | `disableAutocorrection(_:)` | `autocorrectionDisabled(_:)` | iOS 16+ | | `UIPasteboard.general` | `PasteButton` | iOS 16+ | | `onChange(of:perform:)` | `onChange(of:) { }` or `onChange(of:) { old, new in }` | iOS 17+ | +| `UIImpactFeedbackGenerator` / `UISelectionFeedbackGenerator` / `UINotificationFeedbackGenerator` | `sensoryFeedback(_:trigger:)` | iOS 17+ | | `MagnificationGesture` | `MagnifyGesture` | iOS 17+ | | `RotationGesture` | `RotateGesture` | iOS 17+ | | `coordinateSpace(name:)` | `coordinateSpace(.named(...))` | iOS 17+ | From 2c0095b3d48cfd456881f42f7eee46cd7e2cf1b3 Mon Sep 17 00:00:00 2001 From: zunda <47569369+zunda-pixel@users.noreply.github.com> Date: Thu, 2 Apr 2026 02:05:13 +0900 Subject: [PATCH 2/2] Revise guidelines for SwiftUI API usage and haptics Updated operating rules and best practices for SwiftUI development. --- swiftui-expert-skill/SKILL.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/swiftui-expert-skill/SKILL.md b/swiftui-expert-skill/SKILL.md index 4647f46..f12241c 100644 --- a/swiftui-expert-skill/SKILL.md +++ b/swiftui-expert-skill/SKILL.md @@ -9,7 +9,6 @@ description: Write, review, or improve SwiftUI code following best practices for - Consult `references/latest-apis.md` at the start of every task to avoid deprecated APIs - Prefer native SwiftUI APIs over UIKit/AppKit bridging unless bridging is necessary -- Prefer `sensoryFeedback()` over UIKit feedback generators when working in SwiftUI views - Focus on correctness and performance; do not enforce specific architectures (MVVM, VIPER, etc.) - Encourage separating business logic from views for testability without mandating how - Follow Apple's Human Interface Guidelines and API design patterns @@ -77,7 +76,6 @@ These are hard rules -- violations are always bugs: - [ ] `ForEach` uses stable identity (never `.indices` for dynamic content) - [ ] Constant number of views per `ForEach` element - [ ] `.animation(_:value:)` always includes the `value` parameter -- [ ] SwiftUI haptics use `sensoryFeedback()` instead of UIKit feedback generators - [ ] iOS 26+ APIs gated with `#available` and fallback provided - [ ] `import Charts` present in files using chart types