I have an array of 5 custom objects (all objects are of the same custom type, City). The below is the output of typing po cities in my xcode terminal:
▿ 5 elements
▿ 0 : City
▿ name : Name
- rawValue : "Manchester"
▿ description : Optional<String>
- some : "Old Trafford"
▿ 1 : City
▿ name : Name
- rawValue : "London"
▿ description : Optional<String>
- some : "Emirates"
▿ 2 : City
▿ name : Name
- rawValue : "Liverpool"
▿ description : Optional<String>
- some : "Anfield"
▿ 3 : City
▿ name : Name
- rawValue : "Newcastle"
▿ description : Optional<String>
- some : "St James Park"
▿ 4 : City
▿ name : Name
- rawValue : "Norwich"
▿ description : Optional<String>
- some : "Carrow Road"
How can I sort these so the first three items returned from this array are always London , Liverpool, Manchester? The final 2 elements order is irrelevant here.
I've tried forcing the order of the elements by their current array position, i.e. forcing City[0] to move to City[2] - however this isn't suitable as the order I receive the elements within City can change - the position needs to be set based on the output of the specific City rawValue
TIA