Skip to content

Instantly share code, notes, and snippets.

@Yihwan
Created January 9, 2020 22:33
Show Gist options
  • Save Yihwan/cd52f437a6a5767da68d1ef50f18e4e7 to your computer and use it in GitHub Desktop.
Save Yihwan/cd52f437a6a5767da68d1ef50f18e4e7 to your computer and use it in GitHub Desktop.
//
// Haptics.swift
// skills-timer
//
// Created by Yihwan Kim on 1/1/20.
// Copyright © 2020 Yihwan Kim. All rights reserved.
//
import Foundation
import UIKit
struct Haptics {
static let notificationGenerator = UINotificationFeedbackGenerator()
static let lightFeedbackGenerator = UIImpactFeedbackGenerator(style: .light)
static let mediumFeedbackGenerator = UIImpactFeedbackGenerator(style: .medium)
static let heavyFeedbackGenerator = UIImpactFeedbackGenerator(style: .heavy)
static func success() {
Self.notificationGenerator.notificationOccurred(.success)
}
static func warning() {
Self.notificationGenerator.notificationOccurred(.warning)
}
static func light() {
Self.lightFeedbackGenerator.impactOccurred()
}
static func medium() {
Self.mediumFeedbackGenerator.impactOccurred()
}
static func heavy() {
Self.heavyFeedbackGenerator.impactOccurred()
}
}
Copy link

ghost commented Jan 14, 2020

Haptics.success() is so much easier than the alternatives!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment