After the recent update of Xcode, this code that used to work no longer works. Most of the Selector(":") has an auto correction with the exception for this code:
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil);
}
which flags an error:
No method declared with Objective C selector 'keyboardWillSHow:'
This image show different attempts which have all failed.
What is the new syntax for this code?
Swift 3 example:
The swift syntax changed. Try this:
I have had same issues and also find out that the class you refer on must also be subclassed from NSObject (which is not necc. the case in Swift) Otherwise you get the message
Assign the
Selector
as below:And the method to update what you want:
Same way you can do for
UIKeyboardWillHideNotification
.Swift 3 syntax (just like Sohil's above):