Code Code - 1 year ago 48
Swift Question

what does the "force" parameter do in UIView.endEditing?

In what situation will

self.view.endEditing(true)
and
self.view.endEditing(false)
produce different results?




The docs for
func endEditing(force: Bool) -> Bool
states the following for the parameter
force
.


Specify true to force the first responder to resign, regardless of whether it wants to do so.

Answer Source

As the comment mentioned, if canResignFirstResponder returns false, self.view.endEditing(true) will cause the control to lose focus but self.view.endEditing(false) will not.