3

I'm trying to update this code from Swift 3 to Swift 4.2

NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidShow), name: .UIKeyboardDidShow, object: nil); 

So far, I've just tried the auto corrections given by the compiler. This results in code like this:

NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidShow), name: .UIResponder.keyboardDidShowNotification, object: nil); 

Unfortunately, that doesn't take me far, resulting in additional error: "Type of expression is ambiguous without more context"
Has anyone solved this please? enter image description here

1 Answer 1

8

Just replace .UIResponder.keyboardDidShowNotification with UIResponder.keyboardDidShowNotification and it will solve your problem.

And final code will be:

NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.