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?

Sh_Khan
  • 93,445
  • 7
  • 57
  • 76
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
  • 216,610
  • 56
  • 458
  • 536