Code Code - 5 months ago 15
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

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.