I am having trouble trying to migrate my piece of code from Swift 3 to Swift 4.2
here is the current code to be migrated:
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardHide), name: .UIKeyboardWillHide, object: nil)
}
Here's what I have managed to do :
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow), name: NSNotification.Name.UIResponder.UIKeyboardWillShowNotification, object: nil)
}
And still I get the error:
Type of expression is ambiguous without more context
I've been all day coding, so I can't really even see what's wrong with this code. Can anybody help me solve this?
You are making things too complicated than it should be...
With this code, Xcode 10 will show you the right fix-it suggestion.
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow),
name: UIKeyboardWillShowNotification, object: nil)
}
My Xcode 10 has fixed it as:
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow),
name: UIResponder.keyboardWillShowNotification, object: nil)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With