Skip to content

Instantly share code, notes, and snippets.

@taktamur
Created June 28, 2014 10:02
Show Gist options
  • Save taktamur/ae39cbcbbdabe41d897f to your computer and use it in GitHub Desktop.
Save taktamur/ae39cbcbbdabe41d897f to your computer and use it in GitHub Desktop.
Swift Dictionary sort array
// https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/swift_programming_language/Closures.html
let data:Dictionary = [30:"value1", 20:"2", 10:"3"]
println("patter 1")
for key in sort(Array(data.keys), { (a:Int,b:Int) -> Bool in return a > b }) {
println( data[key] )
}
println("patter 2")
for key in sort(Array(data.keys), { return $0 > $1 }) {
println( data[key] )
}
println("patter 3")
for key in sort(Array(data.keys), {$0 > $1 }) {
println( data[key] )
}
println("patter 4")
for key in sort(Array(data.keys), >) {
println( data[key] )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment