---
title: "init(keyPath:ascending:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nssortdescriptor/init(keypath:ascending:)"
---

# init(keyPath:ascending:)

Creates a sort descriptor with a specified key path and ordering.

## Declaration

```swift
convenience init<Root, Value>(keyPath: KeyPath<Root, Value>, ascending: Bool)
```

## Parameters

- `keyPath`: The key path to the property to compare.
- `ascending`: If true, the sort descriptor compares using the doc://com.apple.foundation/documentation/Foundation/SortOrder/forward sort order; otherwise, it uses doc://com.apple.foundation/documentation/Foundation/SortOrder/reverse.

## See Also

### Creating a Sort Descriptor

- [init(key:ascending:)](foundation/nssortdescriptor/init(key:ascending:).md)
- [init(key:ascending:selector:)](foundation/nssortdescriptor/init(key:ascending:selector:).md)
- [init(key:ascending:comparator:)](foundation/nssortdescriptor/init(key:ascending:comparator:).md)
- [init(keyPath:ascending:comparator:)](foundation/nssortdescriptor/init(keypath:ascending:comparator:).md)
- [init(coder:)](foundation/nssortdescriptor/init(coder:).md)
- [init(_:)](foundation/nssortdescriptor/init(_:)-7qf91.md)
