<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSMatrix/textShouldEndEditing(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMatrix(im)textShouldEndEditing:"
  },
  "title" : "textShouldEndEditing(_:)"
}
-->

# textShouldEndEditing(_:)

Requests permission to end editing.

```
func textShouldEndEditing(_ textObject: NSText) -> Bool
```

## Parameters

`textObject`

The text object requesting permission to end editing.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the text object should proceed to finish editing and resign first responder status. If the delegate returns <doc://com.apple.documentation/documentation/Swift/false>, the text object selects all of its text and remains the first responder.

## Discussion

The [`NSMatrix`](/documentation/AppKit/NSMatrix) method returns <doc://com.apple.documentation/documentation/Swift/false> if the text field contains invalid contents; otherwise it returns the value passed back from [`control(_:textShouldEndEditing:)`](/documentation/AppKit/NSControlTextEditingDelegate/control(_:textShouldEndEditing:)).

This method is invoked to let the [`NSTextField`](/documentation/AppKit/NSTextField) respond to impending loss of first-responder status. This method’s default behavior checks the text field for validity; providing that the field contents are deemed valid, and providing that the delegate responds, [`control(_:textShouldEndEditing:)`](/documentation/AppKit/NSControlTextEditingDelegate/control(_:textShouldEndEditing:)) is sent to the receiver’s delegate (passing the receiver and `textObject` as parameters).

## See Also

[`delegate`](/documentation/AppKit/NSMatrix/delegate)

The delegate for messages from the field editor.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)