<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTreeNode/sort(with:recursively:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTreeNode(im)sortWithSortDescriptors:recursively:"
  },
  "title" : "sort(with:recursively:)"
}
-->

# sort(with:recursively:)

Sorts the receiver’s subtree using the values of the represented objects with the specified sort descriptors.

```
func sort(with sortDescriptors: [NSSortDescriptor], recursively: Bool)
```

## Parameters

`sortDescriptors`

Array of sort descriptors specifying how to sort the represented objects.

`recursively`

A Boolean that specifies whether the child nodes should be sorted recursively.

## Discussion

All the represented objects in the child nodes must be key-value coding compliant for the keys specified in the sort descriptors.

---

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)