Skip to content

Instantly share code, notes, and snippets.

@yarshure
Created February 2, 2016 02:04
Show Gist options
  • Select an option

  • Save yarshure/1e5c1b032da8a37485d5 to your computer and use it in GitHub Desktop.

Select an option

Save yarshure/1e5c1b032da8a37485d5 to your computer and use it in GitHub Desktop.
Swift version String compare
let target = "1.1.7"
let romver = "1.1.23"
if romver.compare(target, options: NSStringCompareOptions.NumericSearch, range: nil, locale: nil) == NSComparisonResult.OrderedDescending {
print("abc")
}else {
print("def")
}
@hlung

hlung commented Feb 22, 2018

Copy link
Copy Markdown

One weird case. "1.0.0".compare("1.0", options: .numeric, range: nil, locale: nil) gives you .orderedDescending lol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment