---
title: "sortedArray(comparator:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsarray/sortedarray(comparator:)"
---

# sortedArray(comparator:)

Returns an array that lists the receiving array’s elements in ascending order, as determined by the comparison method specified by a given NSComparator block.

## Declaration

```swift
func sortedArray(comparator cmptr: (Any, Any) -> ComparisonResult) -> [Any]
```

## Parameters

- `cmptr`: A comparator block.

## Return Value

Return Value An array that lists the receiving array’s elements in ascending order, as determined by the comparison method specified cmptr.

## See Also

### Sorting

- [sortedArrayHint](foundation/nsarray/sortedarrayhint.md)
- [sortedArray(_:context:)](foundation/nsarray/sortedarray(_:context:).md)
- [sortedArray(_:context:hint:)](foundation/nsarray/sortedarray(_:context:hint:).md)
- [sortedArray(using:)](foundation/nsarray/sortedarray(using:)-82wi1.md)
- [sortedArray(using:)](foundation/nsarray/sortedarray(using:)-9nhh9.md)
- [sortedArray(options:usingComparator:)](foundation/nsarray/sortedarray(options:usingcomparator:).md)
- [Comparator](foundation/comparator.md)
