Skip to content

Instantly share code, notes, and snippets.

@RShergold
Last active August 29, 2015 14:16
Show Gist options
  • Save RShergold/82f64b6abc6d5733f306 to your computer and use it in GitHub Desktop.
Save RShergold/82f64b6abc6d5733f306 to your computer and use it in GitHub Desktop.
swift - sort dictionary of objects
struct Person {
let age = 0
}
let people = ["tom": Person(age: 12), "dick": Person(age: 7), "harry": Person(age: 50)]
var people_array = [Person](people.values) //convert to array
people_array.sort({ $0.age > $1.age }) //sort the array
people_array[0].age // 50
people_array[1].age // 12
people_array[2].age // 7
@RShergold
Copy link
Author

needs update due to apple changing Swift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment