[swift-evolution] [Accepted] SE-0121: Remove Optional Comparison Operators
Magnus Ahltorp
map at kth.se
Sat Aug 27 09:11:29 CDT 2016
> 27 Aug. 2016 15:58 Charlie Monroe via swift-evolution <swift-evolution at swift.org> wrote:
> Now, you need to do:
>
> users.sorted({
> guard let firstName = $0.0.lastName else {
> return true
> }
>
> guard let secondName = $0.1.lastName else {
> return false
> }
>
> return firstName < secondName
> })
Without having tested it, something like this should work. In more complicated cases, make it a method on the struct.
users.sorted({ ($0.lastName ?? "") < ($1.lastName ?? "") })
/Magnus
More information about the swift-evolution
mailing list