Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'Notification.Name' (aka 'NSNotification.Name') has no member 'UIDevice'

Tags:

swift

swift4.2

Here is my code which was working before.

NotificationCenter.default.addObserver(self, selector: #selector(ImageScrollView.changeOrientationNotification), name: Notification.Name.UIDevice.orientationDidChangeNotification, object: nil)
like image 888
Code Hunter Avatar asked Dec 03 '22 18:12

Code Hunter


2 Answers

Remove Notification.Name. prefix:

NotificationCenter.default.addObserver(self, selector: #selector(ImageScrollView.changeOrientationNotification), name: UIDevice.orientationDidChangeNotification, object: nil)

The constants for notifications names were moved in iOS 12 SDK which came with Xcode 10.

like image 59
Sulthan Avatar answered May 16 '23 08:05

Sulthan


April 9th 2020, I ran into a similar problem. I've got:

name: Notification.Name.UIKeyboardWillHide

And I had to "Replace 'UIKeyboardWillHide' with 'UIResponder.keyboardWillHideNotification'" I clicked "fix" and got:

name: Notification.Name.UIResponder.keyboardWillHideNotification,

After that I got "Type 'Notification.Name' (aka 'NSNotification.Name') has no member 'UIResponder'". And finally, Thanks to you guys, I figured out:

name: UIResponder.keyboardFrameEndUserInfoKey.

Maybe my case and the answer will also help some beginner))

like image 32
Kviki Avatar answered May 16 '23 06:05

Kviki