Skip to content

Instantly share code, notes, and snippets.

@GottaGetSwifty
Created June 12, 2017 22:11
Show Gist options
  • Select an option

  • Save GottaGetSwifty/d53b9c07158d92b59ab14512dc2275d0 to your computer and use it in GitHub Desktop.

Select an option

Save GottaGetSwifty/d53b9c07158d92b59ab14512dc2275d0 to your computer and use it in GitHub Desktop.
var myArray: [[String]] = [
["1", "picture1.png", "John", "Smith"],
["2", "picture2.png", "Mike", "Rutherford"],
]
func sort<T: Comparable>(ArrayOfArrays: [[T]], sortingIndex: Int, sortFunc: (T, T) -> Bool) -> [[T]] {
return ArrayOfArrays.sorted { sortFunc($0[sortingIndex], $1[sortingIndex])}
}
print(sort(ArrayOfArrays: myArray, sortingIndex: 0, sortFunc: <))
//[["1", "picture1.png", "John", "Smith"], ["2", "picture2.png", "Mike", "Rutherford"]]
print(sort(ArrayOfArrays: myArray, sortingIndex: 0, sortFunc: >))
//[["2", "picture2.png", "Mike", "Rutherford"], ["1", "picture1.png", "John", "Smith"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment