Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Created February 10, 2019 09:33
Show Gist options
  • Save KentarouKanno/b907036569ba513d4a0b60fab5c5c1f3 to your computer and use it in GitHub Desktop.
Save KentarouKanno/b907036569ba513d4a0b60fab5c5c1f3 to your computer and use it in GitHub Desktop.
extension UIFeedbackGenerator {

    static func notificationFeedback(style: UINotificationFeedbackGenerator.FeedbackType = .success) {
        let generator = UINotificationFeedbackGenerator()
        generator.prepare()
        generator.notificationOccurred(style)
    }

    static func impactFeedback(style: UIImpactFeedbackGenerator.FeedbackStyle = .medium) {
        let generator = UIImpactFeedbackGenerator(style: style)
        generator.prepare()
        generator.impactOccurred()
    }

    static func selectionFeedback() {
        let generator = UISelectionFeedbackGenerator()
        generator.prepare()
        generator.selectionChanged()
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment