Learn how to work with Xcode Previews in SwiftData App. SwiftData in combination with SwiftUI…
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!