Skip to content

Instantly share code, notes, and snippets.

@tadija
Last active October 26, 2021 18:44
Show Gist options
  • Save tadija/88779a34d66bb5acff5c9513c78fe885 to your computer and use it in GitHub Desktop.
Save tadija/88779a34d66bb5acff5c9513c78fe885 to your computer and use it in GitHub Desktop.
AEHaptic
/**
* https://gist.github.com/tadija/88779a34d66bb5acff5c9513c78fe885
* Revision 5
* Copyright © 2018-2021 Marko Tadić
* Licensed under the MIT license
*/
import UIKit
@available(iOS 10.0, *)
public struct AEHaptic {
public static func success() {
let feedback = UINotificationFeedbackGenerator()
feedback.notificationOccurred(.success)
}
public static func warning() {
let feedback = UINotificationFeedbackGenerator()
feedback.notificationOccurred(.warning)
}
public static func error() {
let feedback = UINotificationFeedbackGenerator()
feedback.notificationOccurred(.error)
}
public static func impactLight() {
let feedback = UIImpactFeedbackGenerator(style: .light)
feedback.impactOccurred()
}
public static func impactMedium() {
let feedback = UIImpactFeedbackGenerator(style: .medium)
feedback.impactOccurred()
}
public static func impactHeavy() {
let feedback = UIImpactFeedbackGenerator(style: .heavy)
feedback.impactOccurred()
}
public static func selection() {
let feedback = UISelectionFeedbackGenerator()
feedback.selectionChanged()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment