0

At the moment I am doing this :

arrayOfStruct.sort { $0.name < $1.name }

arrayOfStruct.sort { $0.subregion < $1.subregion }

arrayOfStruct.sort { $0.region < $1.region }

it works fine to sort names within subregions within regions but the questions is how can I do it smarter?

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
BernieW
  • 17
  • 2

1 Answers1

2

If your sort has up to six members you can simply use a single sort passing a tuple:

arrayOfStruct.sort { ($0.region, $0.subregion, $0.name) < ($1.region, $1.subregion, $1.name) }
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571