# Sorting an array based on the value of a property

**URL:** <https://forums.swift.org/t/sorting-an-array-based-on-the-value-of-a-property/28911>\
**Category:** Using Swift\
**Created:** [September 17, 2019, 8:44pm UTC](https://forums.swift.org/t/sorting-an-array-based-on-the-value-of-a-property/28911 "2019-09-17T20:44:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Lantua](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lantua/32/8868_2.png) [@Lantua](https://forums.swift.org/u/Lantua)\
**Post date:** [September 17, 2019, 8:46pm UTC](https://forums.swift.org/t/sorting-an-array-based-on-the-value-of-a-property/28911/2 "2019-09-17T20:46:39Z")

</div>

`sort(by:)` is probably the easiest right now, other than conforming `Foo` to `Comparable`.

```swift
sort { $0.numbers[0] < $1.numbers[0] }

```

There's also this pitch: [Map Sorting](https://forums.swift.org/t/map-sorting/21421)

---

_[View the full topic](https://forums.swift.org/t/sorting-an-array-based-on-the-value-of-a-property/28911)._
