Skip to content

Instantly share code, notes, and snippets.

@perlmunger
Created January 18, 2017 03:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlmunger/9e326b726931e6d87b07b936e4067fa1 to your computer and use it in GitHub Desktop.
Save perlmunger/9e326b726931e6d87b07b936e4067fa1 to your computer and use it in GitHub Desktop.
Swift sort strings numerically array extension
extension Sequence where Iterator.Element == String {
var sortedByNumberAndString : [String] {
return self.sorted { (s1, s2) -> Bool in
return s1.compare(s2, options: .numeric) == .orderedAscending
}
}
}
let sorted = ["8 Bob", "7 Joe", "11 Jimmy", "9 Larry", "1 Kyle"].sortedByNumberAndString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment