isFirstResponder is false even after becomeFirstResponder is true

248 Views Asked by At

I'm debugging code to see why a WKWebView's instance doesn't become the firstResponder by doing the following:

override func becomeFirstResponder() -> Bool {
    let becomeFirstResponserResponse = super.becomeFirstResponder()
    print(becomeFirstResponserResponse, self.isFirstResponder)
    return becomeFirstResponserResponse
}

This prints out true, false. I've also verified that the web view's window property isn't nil.

As per Apple's documentation, becomeFirstResponder returns true if this object is now the first responder; otherwise, false.. So I'd expect self.isFirstResponder to be true. What am I understanding incorrectly?

1

There are 1 best solutions below

2
matt On

Because you haven't even finished returning from becomeFirstResponder yet! If you were to do your print inside a half-second delay you would find that we are in fact now returning true from isFirstResponder as well.