Sort array on two parameters in swift

Solutions Collect From Internet About “Sort array on two parameters in swift”

Your syntax looks correct. Just change the closure to

return o1.name == o2.name ? (o1.description < o2.description) : (o1.name < o2.name)

If you want more than two sort criteria I recommend using the old fashioned sort descriptors.

let sortedArray = (unsortedArray as NSArray).sortedArrayUsingDescriptors([
  NSSortDescriptor(key: "name", ascending: true),
  NSSortDescriptor(key: "description", ascending: true),
  .... 
]) as! [Object]