Kunal Shah
Kunal Shah

Reputation: 1121

isFirstResponder is false even after becomeFirstResponder is true

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?

Upvotes: 0

Views: 327

Answers (1)

matt
matt

Reputation: 535306

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.

Upvotes: 2

Related Questions