# Sort \`Collection\` using \`KeyPath\`

**URL:** <https://forums.swift.org/t/sort-collection-using-keypath/14554>\
**Category:** Pitches\
**Created:** [July 18, 2018, 3:31am UTC](https://forums.swift.org/t/sort-collection-using-keypath/14554 "2018-07-18T03:31:59Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![Jon\_Hull](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_hull/32/678_2.png) [@Jon\_Hull](https://forums.swift.org/u/Jon_Hull)\
**Post date:** [July 19, 2018, 2:12am UTC](https://forums.swift.org/t/sort-collection-using-keypath/14554/14 "2018-07-19T02:12:39Z")

</div>

> [@cal](#):
>
> Within the context of this pitch, my ideal call-site syntax for doing advanced String comparisons would look like this:
> 
> ```swift
> OS.supported.sorted(by: \.name, using: .caseInsensitiveCompare)
> OS.supported.sorted(by: \.name, using: .localizedCaseInsensitveCompare)
> 
> ```
> 
> The trouble is those methods are currently `(String) -> (String) -> ComparisonResult` , so it's not immediately compatible with `(String, String) -> Bool` .
> 
> You'd currently have to write something like this:
> 
> ```swift
> OS.supported.sorted(by: \.name, using: { $0.caseInsensitiveCompare($1) == .orderedAscending })
> 
> ```

Hmm... maybe the best way to spell this is to put a localization normalization method on string:

```
OS.supported.sorted(by: \name.lowercased)
OS.supported.sorted(by: \name.normalized)

```

---

_[View the full topic](https://forums.swift.org/t/sort-collection-using-keypath/14554)._
