Skip to content

Instantly share code, notes, and snippets.

@ericdke
Created March 12, 2016 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericdke/ae8c535ef54dce1276cb to your computer and use it in GitHub Desktop.
Save ericdke/ae8c535ef54dce1276cb to your computer and use it in GitHub Desktop.
Get strings containing non padded numbers sorted properly by numeric order
let names = ["h8", "h9", "h10", "h11", "h4", "h12", "h5", "h6"]
let result = names.sort { $0.compare($1, options: .NumericSearch) == .OrderedAscending }
result // ["h4", "h5", "h6", "h8", "h9", "h10", "h11", "h12"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment