$npx -y skills add johnrogers/claude-swift-engineering --skill hapticsUse when adding haptic feedback for user confirmations (button presses, toggles, purchases), error notifications, or custom tactile patterns (Core Haptics). Covers UIFeedbackGenerator and CHHapticEngine patterns.
| 1 | # Haptics |
| 2 | |
| 3 | Haptic feedback provides tactile confirmation of user actions and system events. When designed thoughtfully, haptics transform interfaces from functional to delightful. |
| 4 | |
| 5 | ## Overview |
| 6 | |
| 7 | Haptics should enhance interactions, not dominate them. The core principle: haptic feedback is like sound design—every haptic should have purpose (confirmation, error, warning), timing (immediate or delayed), and restraint (less is more). |
| 8 | |
| 9 | ## Reference Loading Guide |
| 10 | |
| 11 | **ALWAYS load reference files if there is even a small chance the content may be required.** It's better to have the context than to miss a pattern or make a mistake. |
| 12 | |
| 13 | | Reference | Load When | |
| 14 | |-----------|-----------| |
| 15 | | **[UIFeedbackGenerator](references/uifeedbackgenerator.md)** | Using simple impact/selection/notification haptics | |
| 16 | | **[Core Haptics](references/core-haptics.md)** | Creating custom patterns with CHHapticEngine | |
| 17 | | **[AHAP Patterns](references/ahap-patterns.md)** | Working with Apple Haptic Audio Pattern files | |
| 18 | | **[Design Principles](references/design-principles.md)** | Applying Causality, Harmony, Utility framework | |
| 19 | |
| 20 | ## Core Workflow |
| 21 | |
| 22 | 1. **Choose complexity level**: Simple (UIFeedbackGenerator) vs Custom (Core Haptics) |
| 23 | 2. **For simple haptics**: Use UIImpactFeedbackGenerator, UISelectionFeedbackGenerator, or UINotificationFeedbackGenerator |
| 24 | 3. **For custom patterns**: Create CHHapticEngine, define CHHapticEvents, build CHHapticPattern |
| 25 | 4. **Prepare before triggering**: Call `prepare()` to reduce latency |
| 26 | 5. **Apply design principles**: Ensure Causality (timing), Harmony (multimodal), Utility (meaningful) |
| 27 | |
| 28 | ## System Requirements |
| 29 | |
| 30 | - **iOS 10+** for UIFeedbackGenerator |
| 31 | - **iOS 13+** for Core Haptics (CHHapticEngine) |
| 32 | - **iPhone 8+** for Core Haptics hardware support |
| 33 | - **Physical device required** - haptics cannot be tested in Simulator |
| 34 | |
| 35 | ## Common Mistakes |
| 36 | |
| 37 | 1. **Haptic feedback on every action** — Every button doesn't need haptics. Reserve haptics for critical confirmations (purchase, delete, settings change). Over-haptics are annoying and drain battery. |
| 38 | |
| 39 | 2. **Triggering haptics on main thread blocks** — Long haptic patterns can freeze UI briefly. Use background threads or async for Core Haptics `prepare()` calls to prevent jank. |
| 40 | |
| 41 | 3. **Haptic without audio/visual feedback** — Relying ONLY on haptics means deaf or deaf-blind users miss feedback. Always pair haptics with sound or visual response. |
| 42 | |
| 43 | 4. **Ignoring haptic settings** — Some users disable haptics system-wide. Check `UIFeedbackGenerator.isHapticFeedbackEnabled` before triggering. Graceful degradation is required. |
| 44 | |
| 45 | 5. **AHAP file errors silently** — Invalid AHAP files fail silently without errors. Test with Xcode's haptic designer and validate file syntax before shipping. |
| 46 | |
| 47 | 6. **Forgetting battery impact** — Continuous haptic patterns (progress bars, loading states) drain battery fast. Use haptics for state changes only, not ongoing feedback. |