diff --git a/.gitignore b/.gitignore index 5e5d5ce..71049de 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,7 @@ playground.xcworkspace # Carthage # # Add this line if you want to avoid checking in source code from Carthage dependencies. -# Carthage/Checkouts +Carthage/Checkouts Carthage/Build @@ -61,3 +61,5 @@ Carthage/Build fastlane/report.xml fastlane/screenshots + +.DS_Store diff --git a/.gitmodules b/.gitmodules index 3c64704..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "Carthage/Checkouts/Nimble"] - path = Carthage/Checkouts/Nimble - url = https://github.com/Quick/Nimble.git -[submodule "Carthage/Checkouts/Quick"] - path = Carthage/Checkouts/Quick - url = https://github.com/Quick/Quick.git diff --git a/Cartfile.resolved b/Cartfile.resolved index a1a9ada..1e28c51 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -github "Quick/Nimble" "v3.1.0" -github "Quick/Quick" "v0.9.1" +github "Quick/Nimble" "v6.1.0" +github "Quick/Quick" "v1.1.0" diff --git a/Carthage/Checkouts/Nimble b/Carthage/Checkouts/Nimble deleted file mode 160000 index 72878d6..0000000 --- a/Carthage/Checkouts/Nimble +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 72878d6622cf8362d3507cd2e3d341b06580f451 diff --git a/Carthage/Checkouts/Quick b/Carthage/Checkouts/Quick deleted file mode 160000 index 2f03756..0000000 --- a/Carthage/Checkouts/Quick +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2f037560be197f0f5ae992512549bc29fabb3818 diff --git a/MyPlayground.playground/Contents.swift b/MyPlayground.playground/Contents.swift deleted file mode 100644 index 6c1d739..0000000 --- a/MyPlayground.playground/Contents.swift +++ /dev/null @@ -1,69 +0,0 @@ -// : Playground - noun: a place where people can play - -import Cocoa - -var pre1: [String?] = ["alpha", nil] -var pre2: [String?] = ["alpha", "1"] - -// 1.0.0-alpha < 1.0.0-alpha.1 -// 数字が存在するほうがおおきい -pre1[0] == pre2[0] - -switch (pre1[1], pre2[1]) { -case (.Some, .Some): - break -case (.Some, .None): - break -case (.None, .Some): - break -case (.None, .None): - break -} - -"alpha" < "beta" - -var grid2 = Array(count: 16, repeatedValue: nil); - -class Regexp { - let internalRegexp: NSRegularExpression - let pattern: String - - init(_ pattern: String) { - self.pattern = pattern - do { - self.internalRegexp = try NSRegularExpression(pattern: pattern, options: []) - } catch let error as NSError { - print(error.localizedDescription) - self.internalRegexp = NSRegularExpression() - } - } - - func isMatch(input: String) -> Bool { - let inputAsNSString = input as NSString - let matches = self.internalRegexp.matchesInString( - input, - options: [], - range: NSMakeRange(0, inputAsNSString.length) - ) - return matches.count > 0 - } - - func matches(input: String) -> [String]? { - if self.isMatch(input) { - let inputAsNSString = input as NSString - let matches = self.internalRegexp.matchesInString( - input, - options: [], - range: NSMakeRange(0, inputAsNSString.length) - ) - var results: [String] = [] - for i in 0 ..< matches.count { - results.append(inputAsNSString.substringWithRange(matches[i].range)) - } - return results - } - return nil - } -} - -Regexp("^([0-9]+)$").isMatch("1") diff --git a/MyPlayground.playground/contents.xcplayground b/MyPlayground.playground/contents.xcplayground deleted file mode 100644 index 06828af..0000000 --- a/MyPlayground.playground/contents.xcplayground +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/SemanticVersion.xcodeproj/project.pbxproj b/SemanticVersion.xcodeproj/project.pbxproj index 340fa7b..44fb415 100644 --- a/SemanticVersion.xcodeproj/project.pbxproj +++ b/SemanticVersion.xcodeproj/project.pbxproj @@ -8,17 +8,15 @@ /* Begin PBXBuildFile section */ 0D3425EB1C8C6C5900D32DE1 /* SemanticVersion.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D3425EA1C8C6C5900D32DE1 /* SemanticVersion.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 0D3425F21C8C6C5900D32DE1 /* SemanticVersion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D3425E71C8C6C5900D32DE1 /* SemanticVersion.framework */; }; 0D3425F71C8C6C5900D32DE1 /* SemanticVersionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D3425F61C8C6C5900D32DE1 /* SemanticVersionTests.swift */; }; - 0D3426171C8C703800D32DE1 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D3426161C8C703800D32DE1 /* Nimble.framework */; }; - 0D3426191C8C704400D32DE1 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D3426181C8C704400D32DE1 /* Quick.framework */; }; 0D34261B1C8C719900D32DE1 /* SemanticVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D34261A1C8C719900D32DE1 /* SemanticVersion.swift */; }; 0D34261E1C8C880300D32DE1 /* Regexp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D34261D1C8C880300D32DE1 /* Regexp.swift */; }; 0D3426201C8C8B9400D32DE1 /* RegexpTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D34261F1C8C8B9400D32DE1 /* RegexpTests.swift */; }; - 0D3426211C8C8C1F00D32DE1 /* Regexp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D34261D1C8C880300D32DE1 /* Regexp.swift */; }; 0DCEEC7D1C9409F000504CDE /* SemanticVersionParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DCEEC7C1C9409F000504CDE /* SemanticVersionParser.swift */; }; 0DCEEC7F1C940CC900504CDE /* SemanticVersionParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DCEEC7E1C940CC900504CDE /* SemanticVersionParserTests.swift */; }; - 0DCEEC811C940F7800504CDE /* SemanticVersionParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DCEEC7C1C9409F000504CDE /* SemanticVersionParser.swift */; }; + 4F78DD461EA8E61E005C3573 /* Regexp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D34261D1C8C880300D32DE1 /* Regexp.swift */; }; + 4F78DD471EA8E621005C3573 /* SemanticVersionParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DCEEC7C1C9409F000504CDE /* SemanticVersionParser.swift */; }; + 4F78DD481EA8E627005C3573 /* SemanticVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D34261A1C8C719900D32DE1 /* SemanticVersion.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -32,20 +30,17 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 0D3425E71C8C6C5900D32DE1 /* SemanticVersion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SemanticVersion.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 0D3425EA1C8C6C5900D32DE1 /* SemanticVersion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SemanticVersion.h; sourceTree = ""; }; 0D3425EC1C8C6C5900D32DE1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 0D3425F11C8C6C5900D32DE1 /* SemanticVersionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SemanticVersionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0D3425F61C8C6C5900D32DE1 /* SemanticVersionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SemanticVersionTests.swift; sourceTree = ""; }; 0D3425F81C8C6C5900D32DE1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 0D3426161C8C703800D32DE1 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = "Carthage/Checkouts/Nimble/build/Debug-iphoneos/Nimble.framework"; sourceTree = ""; }; - 0D3426181C8C704400D32DE1 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = "Carthage/Checkouts/Quick/build/Debug-iphoneos/Quick.framework"; sourceTree = ""; }; 0D34261A1C8C719900D32DE1 /* SemanticVersion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SemanticVersion.swift; sourceTree = ""; }; 0D34261D1C8C880300D32DE1 /* Regexp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Regexp.swift; sourceTree = ""; }; 0D34261F1C8C8B9400D32DE1 /* RegexpTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegexpTests.swift; sourceTree = ""; }; - 0DCA81941CA640490076F9EB /* MyPlayground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = MyPlayground.playground; sourceTree = ""; }; 0DCEEC7C1C9409F000504CDE /* SemanticVersionParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SemanticVersionParser.swift; sourceTree = ""; }; 0DCEEC7E1C940CC900504CDE /* SemanticVersionParserTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SemanticVersionParserTests.swift; sourceTree = ""; }; + 4FB43BFE1EA8E860003AFA4E /* SemanticVersion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = SemanticVersion.framework; path = "/Users/atsushi.sakai/Workspace/SemanticVersion/build/Debug-iphoneos/SemanticVersion.framework"; sourceTree = ""; }; + 4FB43BFF1EA8E860003AFA4E /* SemanticVersionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; name = SemanticVersionTests.xctest; path = "/Users/atsushi.sakai/Workspace/SemanticVersion/build/Debug-iphoneos/SemanticVersionTests.xctest"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -60,9 +55,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 0D3426191C8C704400D32DE1 /* Quick.framework in Frameworks */, - 0D3426171C8C703800D32DE1 /* Nimble.framework in Frameworks */, - 0D3425F21C8C6C5900D32DE1 /* SemanticVersion.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -72,24 +64,11 @@ 0D3425DD1C8C6C5900D32DE1 = { isa = PBXGroup; children = ( - 0DCA81941CA640490076F9EB /* MyPlayground.playground */, - 0D3426181C8C704400D32DE1 /* Quick.framework */, - 0D3426161C8C703800D32DE1 /* Nimble.framework */, 0D3425E91C8C6C5900D32DE1 /* SemanticVersion */, 0D3425F51C8C6C5900D32DE1 /* SemanticVersionTests */, - 0D3425E81C8C6C5900D32DE1 /* Products */, ); sourceTree = ""; }; - 0D3425E81C8C6C5900D32DE1 /* Products */ = { - isa = PBXGroup; - children = ( - 0D3425E71C8C6C5900D32DE1 /* SemanticVersion.framework */, - 0D3425F11C8C6C5900D32DE1 /* SemanticVersionTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; 0D3425E91C8C6C5900D32DE1 /* SemanticVersion */ = { isa = PBXGroup; children = ( @@ -150,7 +129,7 @@ ); name = SemanticVersion; productName = SemanticVersion; - productReference = 0D3425E71C8C6C5900D32DE1 /* SemanticVersion.framework */; + productReference = 4FB43BFE1EA8E860003AFA4E /* SemanticVersion.framework */; productType = "com.apple.product-type.framework"; }; 0D3425F01C8C6C5900D32DE1 /* SemanticVersionTests */ = { @@ -168,7 +147,7 @@ ); name = SemanticVersionTests; productName = SemanticVersionTests; - productReference = 0D3425F11C8C6C5900D32DE1 /* SemanticVersionTests.xctest */; + productReference = 4FB43BFF1EA8E860003AFA4E /* SemanticVersionTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -178,14 +157,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0830; ORGANIZATIONNAME = "Atsushi Sakai"; TargetAttributes = { 0D3425E61C8C6C5900D32DE1 = { CreatedOnToolsVersion = 7.2.1; + LastSwiftMigration = 0830; }; 0D3425F01C8C6C5900D32DE1 = { CreatedOnToolsVersion = 7.2.1; + LastSwiftMigration = 0830; }; }; }; @@ -197,7 +178,7 @@ en, ); mainGroup = 0D3425DD1C8C6C5900D32DE1; - productRefGroup = 0D3425E81C8C6C5900D32DE1 /* Products */; + productRefGroup = 0D3425DD1C8C6C5900D32DE1; projectDirPath = ""; projectRoot = ""; targets = ( @@ -239,11 +220,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4F78DD481EA8E627005C3573 /* SemanticVersion.swift in Sources */, 0D3426201C8C8B9400D32DE1 /* RegexpTests.swift in Sources */, - 0DCEEC811C940F7800504CDE /* SemanticVersionParser.swift in Sources */, + 4F78DD471EA8E621005C3573 /* SemanticVersionParser.swift in Sources */, 0D3425F71C8C6C5900D32DE1 /* SemanticVersionTests.swift in Sources */, + 4F78DD461EA8E61E005C3573 /* Regexp.swift in Sources */, 0DCEEC7F1C940CC900504CDE /* SemanticVersionParserTests.swift in Sources */, - 0D3426211C8C8C1F00D32DE1 /* Regexp.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -271,8 +253,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -300,6 +284,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -319,8 +304,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -340,6 +327,8 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -351,6 +340,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -362,6 +352,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -369,6 +360,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -379,6 +371,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.radioboo.SemanticVersion; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -394,6 +387,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.radioboo.SemanticVersionTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -409,6 +403,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.radioboo.SemanticVersionTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/SemanticVersion.xcodeproj/xcshareddata/xcschemes/SemanticVersion.xcscheme b/SemanticVersion.xcodeproj/xcshareddata/xcschemes/SemanticVersion.xcscheme index c4a5cba..184929f 100644 --- a/SemanticVersion.xcodeproj/xcshareddata/xcschemes/SemanticVersion.xcscheme +++ b/SemanticVersion.xcodeproj/xcshareddata/xcschemes/SemanticVersion.xcscheme @@ -1,6 +1,6 @@ Bool { + func isMatch(_ input: String) -> Bool { let inputAsNSString = input as NSString - let matches = self.internalRegexp.matchesInString( - input, + let matches = self.internalRegexp.matches( + in: input, options: [], range:NSMakeRange(0, inputAsNSString.length) ) return matches.count > 0 } - func matches(input: String) -> [String]? { + func matches(_ input: String) -> [String]? { if self.isMatch(input) { let inputAsNSString = input as NSString - let matches = self.internalRegexp.matchesInString( - input, + let matches = self.internalRegexp.matches( + in: input, options: [], range:NSMakeRange(0, inputAsNSString.length) ) var results: [String] = [] for i in 0 ..< matches.count { - results.append( inputAsNSString.substringWithRange(matches[i].range) ) + results.append( inputAsNSString.substring(with: matches[i].range) ) } return results } return nil } -} \ No newline at end of file +} diff --git a/SemanticVersion/SemanticVersion.h b/SemanticVersion/SemanticVersion.h index 1b3768a..5f72210 100644 --- a/SemanticVersion/SemanticVersion.h +++ b/SemanticVersion/SemanticVersion.h @@ -2,7 +2,7 @@ // SemanticVersion.h // SemanticVersion // -// Created by 酒井篤 on 2016/03/06. +// Created by atsushi.sakai on 2016/03/06. // Copyright © 2016年 Atsushi Sakai. All rights reserved. // diff --git a/SemanticVersion/SemanticVersion.swift b/SemanticVersion/SemanticVersion.swift index 01152dd..dc496ab 100644 --- a/SemanticVersion/SemanticVersion.swift +++ b/SemanticVersion/SemanticVersion.swift @@ -2,13 +2,28 @@ // SemanticVersion.swift // SemanticVersion // -// Created by 酒井篤 on 2016/03/06. +// Created by atsushi.sakai on 2016/03/06. // Copyright © 2016年 Atsushi Sakai. All rights reserved. // import Foundation -public class SemanticVersion { +fileprivate func < (lhs: T, rhs: T) -> Bool { + switch (lhs, rhs) { + case let (l, r): + return l < r + } +} + +fileprivate func > (lhs: T, rhs: T) -> Bool { + switch (lhs, rhs) { + case let (l, r): + return l > r + } +} + + +open class SemanticVersion { let major: Int let minor: Int let patch: Int @@ -18,8 +33,8 @@ public class SemanticVersion { public init(_ string: String) { let matched = SemanticVersionParser.parse(string) - let full_versions: [String] = matched.componentsSeparatedByString("-").flatMap({ String($0) }) - let versions = full_versions[0].componentsSeparatedByString(".").flatMap({ Int($0) }) + let full_versions: [String] = matched.components(separatedBy: "-").flatMap({ String($0) }) + let versions = full_versions[0].components(separatedBy: ".").flatMap({ Int($0) }) self.major = versions[0] self.minor = versions[1] self.patch = versions[2] @@ -27,7 +42,7 @@ public class SemanticVersion { return } - let additional: [String] = full_versions[1].componentsSeparatedByString("+").flatMap({ String($0) }) + let additional: [String] = full_versions[1].components(separatedBy: "+").flatMap({ String($0) }) self.prerelease = additional[0] if additional.count < 2 { return @@ -57,21 +72,21 @@ public func > (lhs: SemanticVersion, rhs: SemanticVersion) -> Bool { // for example: 1.0.0 > 1.0.0-rc.1 switch (lhs.prerelease, rhs.prerelease) { - case (.Some, .None): + case (.some, .none): return false - case (.None, .Some): + case (.none, .some): return true - case (.None, .None): + case (.none, .none): return false - case (.Some, .Some): + case (.some, .some): break } - guard let lhs_pair = lhs.prerelease?.componentsSeparatedByString(".").map({ String?($0) }) else { fatalError() } - guard let rhs_pair = rhs.prerelease?.componentsSeparatedByString(".").map({ String?($0) }) else { fatalError() } + guard let lhs_pair = lhs.prerelease?.components(separatedBy: ".").map({ String?($0) }) else { fatalError() } + guard let rhs_pair = rhs.prerelease?.components(separatedBy: ".").map({ String?($0) }) else { fatalError() } if lhs_pair[0] != rhs_pair[0] { - return lhs_pair[0] > rhs_pair[0] + return lhs_pair[0]! > rhs_pair[0]! } // for example: 1.0.0-rc.1 > 1.0.0-rc @@ -82,19 +97,18 @@ public func > (lhs: SemanticVersion, rhs: SemanticVersion) -> Bool { let lhs_number = lhs_pair.count >= 2 ? lhs_pair[1]: nil let rhs_number = rhs_pair.count >= 2 ? rhs_pair[1]: nil switch (lhs_number, rhs_number) { - case (.Some, .Some): - // Int同士, String同士で比較 + case (.some, .some): let regexp_num = Regexp("^([0-9]+)$") if regexp_num.isMatch(lhs_number!) && regexp_num.isMatch(rhs_number!) { - return Int(lhs_number!) > Int(rhs_number!) + return Int(lhs_number!)! > Int(rhs_number!)! } else { return lhs_number! > rhs_number! } - case (.Some, .None): + case (.some, .none): return true - case (.None, .Some): + case (.none, .some): return false - case (.None, .None): + case (.none, .none): return false } } diff --git a/SemanticVersion/SemanticVersionParser.swift b/SemanticVersion/SemanticVersionParser.swift index 558835a..b89854f 100644 --- a/SemanticVersion/SemanticVersionParser.swift +++ b/SemanticVersion/SemanticVersionParser.swift @@ -2,7 +2,7 @@ // SemanticVersionParser.swift // SemanticVersion // -// Created by 酒井篤 on 2016/03/12. +// Created by atsushi.sakai on 2016/03/12. // Copyright © 2016年 Atsushi Sakai. All rights reserved. // @@ -11,7 +11,7 @@ import Foundation class SemanticVersionParser { static let DEFAULT_REGEXP = Regexp("^([0-9]+\\.[0-9]+\\.[0-9]+)(?:-([0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*))?(?:\\+([0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*))?$") - static func parse(input: String) -> String { + static func parse(_ input: String) -> String { guard let matched: String = DEFAULT_REGEXP.matches(input)?.first else { fatalError("can not parse input string to version") } diff --git a/SemanticVersionTests/RegexpTests.swift b/SemanticVersionTests/RegexpTests.swift index 6a10eb9..01d7f71 100644 --- a/SemanticVersionTests/RegexpTests.swift +++ b/SemanticVersionTests/RegexpTests.swift @@ -2,7 +2,7 @@ // RegexpTests.swift // SemanticVersion // -// Created by 酒井篤 on 2016/03/07. +// Created by atsushi.sakai on 2016/03/07. // Copyright © 2016年 Atsushi Sakai. All rights reserved. // @@ -43,7 +43,7 @@ class RegexpTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock { + self.measure { // Put the code you want to measure the time of here. } } diff --git a/SemanticVersionTests/SemanticVersionParserTests.swift b/SemanticVersionTests/SemanticVersionParserTests.swift index a389de9..cbf376a 100644 --- a/SemanticVersionTests/SemanticVersionParserTests.swift +++ b/SemanticVersionTests/SemanticVersionParserTests.swift @@ -2,7 +2,7 @@ // SemanticVersionParserTests.swift // SemanticVersion // -// Created by 酒井篤 on 2016/03/12. +// Created by atsushi.sakai on 2016/03/12. // Copyright © 2016年 Atsushi Sakai. All rights reserved. // diff --git a/SemanticVersionTests/SemanticVersionTests.swift b/SemanticVersionTests/SemanticVersionTests.swift index 785a7db..86b8c27 100644 --- a/SemanticVersionTests/SemanticVersionTests.swift +++ b/SemanticVersionTests/SemanticVersionTests.swift @@ -2,12 +2,11 @@ // SemanticVersionTests.swift // SemanticVersionTests // -// Created by 酒井篤 on 2016/03/06. +// Created by atsushi.sakai on 2016/03/06. // Copyright © 2016年 Atsushi Sakai. All rights reserved. // import XCTest -@testable import SemanticVersion class SemanticVersionTests: XCTestCase {