<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextView/didChangeSelectionNotification",
  "metadataVersion" : "0.1.0",
  "role" : "Type Property",
  "symbol" : {
    "kind" : "Type Property",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:@NSTextViewDidChangeSelectionNotification"
  },
  "title" : "didChangeSelectionNotification"
}
-->

# didChangeSelectionNotification

Posted when the selected range of characters changes.

```
class let didChangeSelectionNotification: NSNotification.Name
```

## Discussion

`NSTextView` posts this notification whenever [`setSelectedRange(_:affinity:stillSelecting:)`](/documentation/AppKit/NSTextView/setSelectedRange(_:affinity:stillSelecting:)) is invoked, either directly or through the many methods ([`mouseDown(with:)`](/documentation/AppKit/NSResponder/mouseDown(with:)), [`selectAll(_:)`](/documentation/AppKit/NSText/selectAll(_:)), and so on) that invoke it indirectly. When the user is selecting text, this notification is posted only once, at the end of the selection operation. The text view’s delegate receives a [`textViewDidChangeSelection(_:)`](/documentation/AppKit/NSTextViewDelegate/textViewDidChangeSelection(_:)) message when this notification is posted.

The notification object is the notifying text view. The `userInfo` dictionary contains the following information:

|Key                             |Value                                                                                    |
|--------------------------------|-----------------------------------------------------------------------------------------|
|`@"NSOldSelectedCharacterRange"`|An `NSValue` object containing an `NSRange` structure with the originally selected range.|

To observe this notification using Swift concurrency, use [`NSTextView.DidChangeSelectionMessage`](/documentation/AppKit/NSTextView/DidChangeSelectionMessage).

---

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)