Different Types of Vibrations - Swift

Feb 21, 2022 1 min read
Different Types of Vibrations - Swift

We are gifted with a wide array of vibrations, from standard to customs. Let's take a look at the simple, already defined by apple vibrations.

Here are all the different types, working with iOS 15 and SwiftUI 3

let generator = UINotificationFeedbackGenerator()

VStack(alignment: .center, spacing: 30.0) {
    Button(action: {
        self.generator.notificationOccurred(.success)
    }) {
        Text("Notification - Success")
    }
    
    Button(action: {
        self.generator.notificationOccurred(.error)
    }) {
        Text("Notification - Error")
    }
    
    Button(action: {
        self.generator.notificationOccurred(.warning)
    }) {
        Text("Notification - Warning")
    }
    
    Button(action: {
        let impactLight = UIImpactFeedbackGenerator(style: .soft)
        impactLight.impactOccurred()
    }) {
        Text("Impact - Soft")
    }
    
    Button(action: {
        let impactLight = UIImpactFeedbackGenerator(style: .light)
        impactLight.impactOccurred()
    }) {
        Text("Impact - Light")
    }
    
    Button(action: {
        let impactMed = UIImpactFeedbackGenerator(style: .medium)
        impactMed.impactOccurred()
    }) {
        Text("Impact - Medium")
    }
    
    Button(action: {
        let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
        impactHeavy.impactOccurred()
    }) {
        Text("Impact - Heavy")
    }
    
    Button(action: {
        let impactLight = UIImpactFeedbackGenerator(style: .rigid)
        impactLight.impactOccurred()
    }) {
        Text("Impact - Rigid")
    }
    
    Button(action: {
        let selectionFeedback = UISelectionFeedbackGenerator()
        selectionFeedback.selectionChanged()
    }) {
        Text("Selection Feedback - Changed")
    }
}
.padding(30)
Great! Next, complete checkout for full access to ArturoFM.
Welcome back! You've successfully signed in.
You've successfully subscribed to ArturoFM.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.