swiftuikithaptic-feedback

I got an error: Use of unresolved identifier 'UINotificationFeedbackGenerator'


When instantiating 'UINotificationFeedbackGenerator' for haptic feedback, I get this compiler error:

Use of unresolved identifier 'UINotificationFeedbackGenerator'

This is how I instantiate it:

   let hapticNotificationFeedback = UINotificationFeedbackGenerator()
   hapticNotificationFeedback?.prepare()
   var hapticImpactFeedback = UIImpactFeedbackGenerator(style: .medium)

I am instantiating this in a view controller extension in a separate file.


Solution

  • Since it's a view controller class extension file, you need to import UIKit in this file as well

    import UIKit