LoginSignup
7
6

More than 5 years have passed since last update.

バージョンを比較する方法

Posted at

http://d.hatena.ne.jp/nakamura001/20100905/1283654296
を参考に勉強中のSwiftで作成してみました。(備忘録)

Swift
        let verA: String! = "1.0.0"
        let verB: String! = "1.41.0"

        if verA.compare(verB, options: NSStringCompareOptions.NumericSearch) == NSComparisonResult.OrderedAscending {
            // 昇順
        }
        else {
            // 昇順では無い
        }
ObjC
    NSString *versionA = @"1.0.0";
    NSString *versionB = @"1.41.0";
    if ([versionA compare:versionB options:NSNumericSearch] == NSOrderedAscending) {
        // 昇順
    } else {
        // 昇順では無い
    }

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6