Skip to content

πŸ‘©πŸ»β€πŸ’» πŸ§‘πŸ½β€πŸ’» Subscribe and Read us on Substack to Get Full Access to Our Posts


SensoryFeedback in SwiftUI – Providing Haptic Feedback

SensoryFeedback in SwiftUI is a potent feature introduced in iOS 17, enabling developers to provide haptic and audio feedback in response to user interactions. This tutorial will walk through various scenarios to integrate SensoryFeedback effectively, enhancing the tactile experience of your apps.

Example 1: Success Feedback on Task Completion

When a user completes a task in an app, providing a success feedback can affirm the action positively.

import SwiftUI

struct TaskCompletionView: View {
    @State private var isDone = false
    
    var body: some View {
        Button("Is Done?") {
            isDone = true
        }.sensoryFeedback(.success, trigger: isDone)
    }
}

This button, when tapped, triggers a success feedback indicating that a task has been successfully completed. This kind of feedback is ideal for to-do lists or goal-tracking apps.

Example 2: Warning Feedback on Potential Issue

...

πŸ”’ The remaining content of this article is only available on our Substack!

Back To Top
Search