---
title: "sort(using:context:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsmatrix/sort(using:context:)"
---

# sort(using:context:)

Sorts the receiver’s cells in ascending order as defined by the specified comparison function.

## Declaration

```swift
func sort(using compare: (Any, Any, UnsafeMutableRawPointer?) -> Int, context: UnsafeMutableRawPointer?)
```

## Parameters

- `compare`: The function to use when comparing cells. The comparison function is used to compare two elements at a time and should return NSOrderedAscending if the first element is smaller than the second, NSOrderedDescending if the first element is larger than the second, and NSOrderedSame if the elements are equal.
- `context`: Context passed to the comparison function as its third argument, each time its called. This allows the comparison to be based on some outside parameter, such as whether character sorting is case-sensitive or case-insensitive.

## See Also

### Related Documentation

- [sort(_:context:)](foundation/nsmutablearray/sort(_:context:).md)

### Laying Out the Cells of the Matrix

- [addColumn()](appkit/nsmatrix/addcolumn().md)
- [addColumn(with:)](appkit/nsmatrix/addcolumn(with:).md)
- [addRow()](appkit/nsmatrix/addrow().md)
- [addRow(with:)](appkit/nsmatrix/addrow(with:).md)
- [cellFrame(atRow:column:)](appkit/nsmatrix/cellframe(atrow:column:).md)
- [cellSize](appkit/nsmatrix/cellsize.md)
- [getNumberOfRows(_:columns:)](appkit/nsmatrix/getnumberofrows(_:columns:).md)
- [insertColumn(_:)](appkit/nsmatrix/insertcolumn(_:).md)
- [insertColumn(_:with:)](appkit/nsmatrix/insertcolumn(_:with:).md)
- [insertRow(_:)](appkit/nsmatrix/insertrow(_:).md)
- [insertRow(_:with:)](appkit/nsmatrix/insertrow(_:with:).md)
- [intercellSpacing](appkit/nsmatrix/intercellspacing.md)
- [makeCell(atRow:column:)](appkit/nsmatrix/makecell(atrow:column:).md)
- [numberOfColumns](appkit/nsmatrix/numberofcolumns.md)
- [numberOfRows](appkit/nsmatrix/numberofrows.md)
