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

# sortedArray(using:)

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

## Declaration

```swift
func sortedArray(using comparator: Selector) -> [Any]
```

## Parameters

- `comparator`: A selector that identifies the method to use to compare two elements at a time. The method should return NSOrderedAscending if the receiving array is smaller than the argument, NSOrderedDescending if the receiving array is larger than the argument, and NSOrderedSame if they are equal.

## Return Value

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

## Discussion

Discussion The new array contains references to the receiving array’s elements, not copies of them. The comparator message is sent to each object in the array and has as its single argument another object in the array. For example, an array of NSString objects can be sorted by using the caseInsensitiveCompare(_:) method declared in the NSString class. Assuming anArray exists, a sorted version of the array can be created in this way:      NSArray *sortedArray =          [anArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

## 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(comparator:)](foundation/nsarray/sortedarray(comparator:).md)
- [sortedArray(options:usingComparator:)](foundation/nsarray/sortedarray(options:usingcomparator:).md)
- [Comparator](foundation/comparator.md)
