Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'NSNotification.Name' has no member 'keyboardDidShowNotification'

I'm getting this error with Swift 4.2

Type 'NSNotification.Name' has no member 'keyboardDidShowNotification'

Here is my code:

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardDidShow(notification:)), name: NSNotification.Name.keyboardDidShowNotification, object: nil) 

Following one was working fine with Swift 4 but not with Swift 4.2

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardDidShow(notification:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil) 

enter image description here

Apple document Ref: NSNotification.Name.keyboardDidShowNotification

like image 434
Krunal Avatar asked Sep 13 '18 15:09

Krunal


1 Answers

I believe you use it like this now.

NotificationCenter.default.addObserver(     self,      selector: #selector(self.keyboardDidShow(notification:)),      name: UIResponder.keyboardDidShowNotification, object: nil)   /* You can substitute UIResponder with any of it's subclass */ 

It is listed in UIResponder doc as a Type Property.

like image 143
Rakesha Shastri Avatar answered Sep 21 '22 09:09

Rakesha Shastri