From fe10b45d41226c3e098faa24ffe51d84fb9d0bc0 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 13:30:19 +0200 Subject: [PATCH 01/19] Return route instead of completion closure --- Sources/Shared/Compass.swift | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Sources/Shared/Compass.swift b/Sources/Shared/Compass.swift index c2bf090..9524a22 100644 --- a/Sources/Shared/Compass.swift +++ b/Sources/Shared/Compass.swift @@ -1,6 +1,13 @@ import Foundation import Sugar +public struct Route { + + public let route: String + public let arguments: [String: String] + public let fragments: [String: AnyObject] +} + public struct Compass { typealias Result = (route: String, arguments: [String: String], @@ -17,14 +24,13 @@ public struct Compass { public static var routes = [String]() - public typealias ParseCompletion = (route: String, arguments: [String : String], fragments: [String : AnyObject]) -> Void - - public static func parse(url: NSURL, fragments: [String : AnyObject] = [:], completion: ParseCompletion) -> Bool { + public static func parse(url: NSURL, fragments: [String : AnyObject] = [:]) -> Route? { let path = url.absoluteString.substringFromIndex(scheme.endIndex) - guard !(path.containsString("?") || path.containsString("#")) - else { return parseAsURL(url, completion: completion) } + guard !(path.containsString("?") || path.containsString("#")) else { + return parseAsURL(url, fragments: fragments) + } let results: [Result] = routes.flatMap { return findMatch($0, pathString: path) @@ -37,31 +43,28 @@ public struct Compass { } if let result = results.first { - completion(route: result.route, arguments: result.arguments, fragments: fragments) - return true + return Route(route: result.route, arguments: result.arguments, fragments: fragments) } - return false + return nil } - static func parseAsURL(url: NSURL, completion: ParseCompletion) -> Bool { - guard let route = url.host else { return false } + static func parseAsURL(url: NSURL, fragments: [String : AnyObject] = [:]) -> Route? { + guard let route = url.host else { return nil } let urlComponents = NSURLComponents(URL: url, resolvingAgainstBaseURL: false) var arguments = [String : String]() urlComponents?.queryItems?.forEach { queryItem in - arguments[queryItem.name] = queryItem.value + arguments[queryItem.name] = queryItem.value } if let fragment = urlComponents?.fragment { - arguments = fragment.queryParameters() + arguments = fragment.queryParameters() } - completion(route: route, arguments: arguments, fragments: [:]) - - return true + return Route(route: route, arguments: arguments, fragments: fragments) } static func findMatch(routeString: String, pathString: String) From 134bd5fcb22a1523b7000a9e1118c5e22149cf08 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 13:30:25 +0200 Subject: [PATCH 02/19] Update tests --- CompassTests/Shared/TestCompass.swift | 266 +++++++++++--------------- 1 file changed, 116 insertions(+), 150 deletions(-) diff --git a/CompassTests/Shared/TestCompass.swift b/CompassTests/Shared/TestCompass.swift index f7546b6..8df424f 100644 --- a/CompassTests/Shared/TestCompass.swift +++ b/CompassTests/Shared/TestCompass.swift @@ -27,271 +27,237 @@ class TestCompass: XCTestCase { } func testParseArguments() { - let expectation = self.expectationWithDescription("Parse arguments") let url = NSURL(string: "compassTests://profile:testUser")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual("profile:{user}", route) - XCTAssertEqual(arguments["user"], "testUser") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual("profile:{user}", route.route) + XCTAssertEqual(route.arguments["user"], "testUser") } func testParseFragments() { - let expectation = self.expectationWithDescription("Parse arguments") let url = NSURL(string: "compassTests://profile:testUser")! - Compass.parse(url, fragments: ["meta" : "foo"]) { route, arguments, fragments in - XCTAssertEqual("profile:{user}", route) - XCTAssertEqual(arguments["user"], "testUser") - XCTAssertEqual("foo" , fragments["meta"] as? String) - - expectation.fulfill() + guard let route = Compass.parse(url, fragments: ["meta" : "foo"]) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual("profile:{user}", route.route) + XCTAssertEqual(route.arguments["user"], "testUser") + XCTAssertEqual("foo" , route.fragments["meta"] as? String) } func testParseRouteConcreateMatchCount() { - let expectation = self.expectationWithDescription("Parse route having concrete match count") let url = NSURL(string: "compassTests://profile:admin")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual("profile:admin", route) - XCTAssert(arguments.isEmpty) - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual("profile:admin", route.route) + XCTAssert(route.arguments.isEmpty) } func testParseRouteWildcardMatchCount() { - let expectation = self.expectationWithDescription("Parse route having wildcard match count") let url = NSURL(string: "compassTests://profile:jack")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual("profile:{user}", route) - XCTAssertEqual(arguments["user"], "jack") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual("profile:{user}", route.route) + XCTAssertEqual(route.arguments["user"], "jack") } func testParseRouteSamePrefix() { - let expectation = self.expectationWithDescription("Parse route having same prefix") let url = NSURL(string: "compassTests://user:list")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual("user:list", route) - XCTAssert(arguments.isEmpty) - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual("user:list", route.route) + XCTAssert(route.arguments.isEmpty) } func testParseMultipleArguments() { - let expectation = self.expectationWithDescription("Parse multiple arguments") let url = NSURL(string: "compassTests://user:list:1:admin")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual("user:list:{userId}:{kind}", route) - XCTAssertEqual(arguments["userId"], "1") - XCTAssertEqual(arguments["kind"], "admin") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual("user:list:{userId}:{kind}", route.route) + XCTAssertEqual(route.arguments["userId"], "1") + XCTAssertEqual(route.arguments["kind"], "admin") } func testParseMultipleArgumentsWithFirstWildcard() { - let expectation = self.expectationWithDescription("Parse multiple arguments with first wild card") let url = NSURL(string: "compassTests://12:user:list:1:admin")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual("{appId}:user:list:{userId}:{kind}", route) - XCTAssertEqual(arguments["appId"], "12") - XCTAssertEqual(arguments["userId"], "1") - XCTAssertEqual(arguments["kind"], "admin") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual("{appId}:user:list:{userId}:{kind}", route.route) + XCTAssertEqual(route.arguments["appId"], "12") + XCTAssertEqual(route.arguments["userId"], "1") + XCTAssertEqual(route.arguments["kind"], "admin") } func testParseWithoutArguments() { - let expectation = self.expectationWithDescription("Parse without arguments") let url = NSURL(string: "compassTests://login")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual("login", route) - XCTAssert(arguments.isEmpty) - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual("login", route.route) + XCTAssert(route.arguments.isEmpty) } func testParseRegularURLWithFragments() { - let expectation = self.expectationWithDescription("Parse URL with fragments") let url = NSURL(string: "compassTests://callback/#access_token=IjvcgrkQk1p7TyJxKa26rzM1wBMFZW6XoHK4t5Gkt1xQLTN8l7ppR0H3EZXpoP0uLAN49oCDqTHsvnEV&token_type=Bearer&expires_in=3600")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual(route, "callback") - XCTAssertEqual(arguments.count, 3) - XCTAssertEqual(arguments["access_token"], "IjvcgrkQk1p7TyJxKa26rzM1wBMFZW6XoHK4t5Gkt1xQLTN8l7ppR0H3EZXpoP0uLAN49oCDqTHsvnEV") - XCTAssertEqual(arguments["expires_in"], "3600") - XCTAssertEqual(arguments["token_type"], "Bearer") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual(route.route, "callback") + XCTAssertEqual(route.arguments.count, 3) + XCTAssertEqual(route.arguments["access_token"], "IjvcgrkQk1p7TyJxKa26rzM1wBMFZW6XoHK4t5Gkt1xQLTN8l7ppR0H3EZXpoP0uLAN49oCDqTHsvnEV") + XCTAssertEqual(route.arguments["expires_in"], "3600") + XCTAssertEqual(route.arguments["token_type"], "Bearer") } func testParseRegularURLWithFragmentsAndGoogleOAuth2AccessToken() { - let expectation = self.expectationWithDescription("Parse URL with fragments and Google OAuth 2.0 access token format") let url = NSURL(string: "compassTests://callback/#access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual(route, "callback") - XCTAssertEqual(arguments.count, 3) - XCTAssertEqual(arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") - XCTAssertEqual(arguments["expires_in"], "3600") - XCTAssertEqual(arguments["token_type"], "Bearer") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual(route.route, "callback") + XCTAssertEqual(route.arguments.count, 3) + XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") + XCTAssertEqual(route.arguments["expires_in"], "3600") + XCTAssertEqual(route.arguments["token_type"], "Bearer") } func testParseRegularURLWithFragmentsAndAlternativeAccessToken() { - let expectation = self.expectationWithDescription("Parse URL with fragments and alternative access token format") let url = NSURL(string: "compassTests://callback/#access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual(route, "callback") - XCTAssertEqual(arguments.count, 3) - XCTAssertEqual(arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") - XCTAssertEqual(arguments["expires_in"], "3600") - XCTAssertEqual(arguments["token_type"], "Bearer") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual(route.route, "callback") + XCTAssertEqual(route.arguments.count, 3) + XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") + XCTAssertEqual(route.arguments["expires_in"], "3600") + XCTAssertEqual(route.arguments["token_type"], "Bearer") } func testParseRegularURLWithSlashQuery() { - let expectation = self.expectationWithDescription("Parse URL with slash query") let url = NSURL(string: "compassTests://callback/?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual(route, "callback") - XCTAssertEqual(arguments.count, 3) - XCTAssertEqual(arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l") - XCTAssertEqual(arguments["expires_in"], "3600") - XCTAssertEqual(arguments["token_type"], "Bearer") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual(route.route, "callback") + XCTAssertEqual(route.arguments.count, 3) + XCTAssertEqual(route.arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l") + XCTAssertEqual(route.arguments["expires_in"], "3600") + XCTAssertEqual(route.arguments["token_type"], "Bearer") } func testParseRegularURLWithSlashQueryAndGoogleOAuth2AccessToken() { - let expectation = self.expectationWithDescription("Parse URL with slash query and Google OAuth 2.0 access token format") let url = NSURL(string: "compassTests://callback/?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual(route, "callback") - XCTAssertEqual(arguments.count, 3) - XCTAssertEqual(arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") - XCTAssertEqual(arguments["expires_in"], "3600") - XCTAssertEqual(arguments["token_type"], "Bearer") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual(route.route, "callback") + XCTAssertEqual(route.arguments.count, 3) + XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") + XCTAssertEqual(route.arguments["expires_in"], "3600") + XCTAssertEqual(route.arguments["token_type"], "Bearer") } func testParseRegularURLWithSlashQueryAndAlternativeAccessToken() { - let expectation = self.expectationWithDescription("Parse URL with slash query and alternative access token format") let url = NSURL(string: "compassTests://callback/?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual(route, "callback") - XCTAssertEqual(arguments.count, 3) - XCTAssertEqual(arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") - XCTAssertEqual(arguments["expires_in"], "3600") - XCTAssertEqual(arguments["token_type"], "Bearer") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual(route.route, "callback") + XCTAssertEqual(route.arguments.count, 3) + XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") + XCTAssertEqual(route.arguments["expires_in"], "3600") + XCTAssertEqual(route.arguments["token_type"], "Bearer") } func testParseRegularURLWithQuery() { - let expectation = self.expectationWithDescription("Parse URL with query") let url = NSURL(string: "compassTests://callback?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual(route, "callback") - XCTAssertEqual(arguments.count, 3) - XCTAssertEqual(arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l") - XCTAssertEqual(arguments["expires_in"], "3600") - XCTAssertEqual(arguments["token_type"], "Bearer") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual(route.route, "callback") + XCTAssertEqual(route.arguments.count, 3) + XCTAssertEqual(route.arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l") + XCTAssertEqual(route.arguments["expires_in"], "3600") + XCTAssertEqual(route.arguments["token_type"], "Bearer") } func testParseRegularURLWithQueryAndGoogleOAuth2AccessToken() { - let expectation = self.expectationWithDescription("Parse URL with query and Google OAuth 2.0 access token format") let url = NSURL(string: "compassTests://callback?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual(route, "callback") - XCTAssertEqual(arguments.count, 3) - XCTAssertEqual(arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") - XCTAssertEqual(arguments["expires_in"], "3600") - XCTAssertEqual(arguments["token_type"], "Bearer") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual(route.route, "callback") + XCTAssertEqual(route.arguments.count, 3) + XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") + XCTAssertEqual(route.arguments["expires_in"], "3600") + XCTAssertEqual(route.arguments["token_type"], "Bearer") } func testParseRegularURLWithQueryAndAlternativeAccessToken() { - let expectation = self.expectationWithDescription("Parse URL with query and alternative access token format") let url = NSURL(string: "compassTests://callback?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")! - Compass.parse(url) { route, arguments, _ in - XCTAssertEqual(route, "callback") - XCTAssertEqual(arguments.count, 3) - XCTAssertEqual(arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") - XCTAssertEqual(arguments["expires_in"], "3600") - XCTAssertEqual(arguments["token_type"], "Bearer") - - expectation.fulfill() + guard let route = Compass.parse(url) else { + XCTFail("Compass parsing failed") + return } - self.waitForExpectationsWithTimeout(4.0, handler:nil) + XCTAssertEqual(route.route, "callback") + XCTAssertEqual(route.arguments.count, 3) + XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") + XCTAssertEqual(route.arguments["expires_in"], "3600") + XCTAssertEqual(route.arguments["token_type"], "Bearer") } } From 3fd3b67ed3b49de12f28e530f505e9828fbbc059 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 13:33:07 +0200 Subject: [PATCH 03/19] Add string extensions --- Sources/Shared/Compass.swift | 1 - Sources/Shared/String+Extensions.swift | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Sources/Shared/String+Extensions.swift diff --git a/Sources/Shared/Compass.swift b/Sources/Shared/Compass.swift index 9524a22..344391e 100644 --- a/Sources/Shared/Compass.swift +++ b/Sources/Shared/Compass.swift @@ -1,5 +1,4 @@ import Foundation -import Sugar public struct Route { diff --git a/Sources/Shared/String+Extensions.swift b/Sources/Shared/String+Extensions.swift new file mode 100644 index 0000000..ad6160f --- /dev/null +++ b/Sources/Shared/String+Extensions.swift @@ -0,0 +1,11 @@ +extension String { + + func split(delimiter: String) -> [String] { + let components = componentsSeparatedByString(delimiter) + return components != [""] ? components : [] + } + + func replace(string: String, with withString: String) -> String { + return stringByReplacingOccurrencesOfString(string, withString: withString) + } +} From 374293c5e1d96f0926840bce1963e19b54107dc8 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 13:33:17 +0200 Subject: [PATCH 04/19] Don't use Sugar --- Compass.xcodeproj/project.pbxproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Compass.xcodeproj/project.pbxproj b/Compass.xcodeproj/project.pbxproj index 9cbf4cc..290d231 100644 --- a/Compass.xcodeproj/project.pbxproj +++ b/Compass.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ BDF7B4171C3FF51800576737 /* Sugar.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BDF7B4161C3FF51800576737 /* Sugar.framework */; }; D20D8C771D0708A800807EB1 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20D8C761D0708A800807EB1 /* Shuffle.swift */; }; D20D8C781D0708A800807EB1 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20D8C761D0708A800807EB1 /* Shuffle.swift */; }; + D5361FE11D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */; }; + D5361FE21D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */; }; D5A2A7931C4CEB1C00B51356 /* Routable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A2A7921C4CEB1C00B51356 /* Routable.swift */; }; D5A2A7971C4CEB7C00B51356 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A2A7961C4CEB7C00B51356 /* Router.swift */; }; D5B2E8AA1C3A780C00C0327D /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5B2E89F1C3A780C00C0327D /* Compass.framework */; }; @@ -50,6 +52,7 @@ BDF7B4141C3FF51100576737 /* Sugar.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sugar.framework; path = Carthage/Build/Mac/Sugar.framework; sourceTree = ""; }; BDF7B4161C3FF51800576737 /* Sugar.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sugar.framework; path = Carthage/Build/iOS/Sugar.framework; sourceTree = ""; }; D20D8C761D0708A800807EB1 /* Shuffle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shuffle.swift; sourceTree = ""; }; + D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; D5A2A7921C4CEB1C00B51356 /* Routable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Routable.swift; sourceTree = ""; }; D5A2A7961C4CEB7C00B51356 /* Router.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; D5B2E89F1C3A780C00C0327D /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -162,6 +165,7 @@ isa = PBXGroup; children = ( BDF7B4081C3FF40300576737 /* Compass.swift */, + D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */, ); path = Shared; sourceTree = ""; @@ -409,6 +413,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D5361FE11D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */, D5A2A7971C4CEB7C00B51356 /* Router.swift in Sources */, BDF7B4091C3FF40300576737 /* Compass.swift in Sources */, D5A2A7931C4CEB1C00B51356 /* Routable.swift in Sources */, @@ -431,6 +436,7 @@ buildActionMask = 2147483647; files = ( BDF7B40A1C3FF40300576737 /* Compass.swift in Sources */, + D5361FE21D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */, BDF7B40C1C3FF40A00576737 /* Compass+Navigate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; From 2cadf50d2037507a79c4425b782d8e8b4067460a Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 13:35:18 +0200 Subject: [PATCH 05/19] Remove references of Sugar --- Compass.xcodeproj/project.pbxproj | 43 ------------------------------- 1 file changed, 43 deletions(-) diff --git a/Compass.xcodeproj/project.pbxproj b/Compass.xcodeproj/project.pbxproj index 290d231..59b2969 100644 --- a/Compass.xcodeproj/project.pbxproj +++ b/Compass.xcodeproj/project.pbxproj @@ -14,8 +14,6 @@ BDF7B40E1C3FF41500576737 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40D1C3FF41500576737 /* Compass+Navigate.swift */; }; BDF7B4101C3FF43F00576737 /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40F1C3FF43F00576737 /* TestCompass.swift */; }; BDF7B4111C3FF43F00576737 /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40F1C3FF43F00576737 /* TestCompass.swift */; }; - BDF7B4151C3FF51100576737 /* Sugar.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BDF7B4141C3FF51100576737 /* Sugar.framework */; }; - BDF7B4171C3FF51800576737 /* Sugar.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BDF7B4161C3FF51800576737 /* Sugar.framework */; }; D20D8C771D0708A800807EB1 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20D8C761D0708A800807EB1 /* Shuffle.swift */; }; D20D8C781D0708A800807EB1 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20D8C761D0708A800807EB1 /* Shuffle.swift */; }; D5361FE11D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */; }; @@ -49,8 +47,6 @@ BDF7B40B1C3FF40A00576737 /* Compass+Navigate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Compass+Navigate.swift"; sourceTree = ""; }; BDF7B40D1C3FF41500576737 /* Compass+Navigate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Compass+Navigate.swift"; sourceTree = ""; }; BDF7B40F1C3FF43F00576737 /* TestCompass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCompass.swift; sourceTree = ""; }; - BDF7B4141C3FF51100576737 /* Sugar.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sugar.framework; path = Carthage/Build/Mac/Sugar.framework; sourceTree = ""; }; - BDF7B4161C3FF51800576737 /* Sugar.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sugar.framework; path = Carthage/Build/iOS/Sugar.framework; sourceTree = ""; }; D20D8C761D0708A800807EB1 /* Shuffle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shuffle.swift; sourceTree = ""; }; D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; D5A2A7921C4CEB1C00B51356 /* Routable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Routable.swift; sourceTree = ""; }; @@ -70,7 +66,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - BDF7B4171C3FF51800576737 /* Sugar.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -86,7 +81,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - BDF7B4151C3FF51100576737 /* Sugar.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -104,8 +98,6 @@ D5B2E8951C3A780C00C0327D = { isa = PBXGroup; children = ( - BDF7B4161C3FF51800576737 /* Sugar.framework */, - BDF7B4141C3FF51100576737 /* Sugar.framework */, D5C629691C3A809D007F7B7C /* Sources */, D5C6295C1C3A800E007F7B7C /* Compass */, D5C6298F1C3A8BDA007F7B7C /* CompassTests */, @@ -251,7 +243,6 @@ D5B2E8A51C3A780C00C0327D /* Sources */, D5B2E8A61C3A780C00C0327D /* Frameworks */, D5B2E8A71C3A780C00C0327D /* Resources */, - D5C629731C3A86E3007F7B7C /* Copy frameworks with Carthage */, ); buildRules = ( ); @@ -288,7 +279,6 @@ D5C629451C3A7FAA007F7B7C /* Sources */, D5C629461C3A7FAA007F7B7C /* Frameworks */, D5C629471C3A7FAA007F7B7C /* Resources */, - D5C629741C3A8717007F7B7C /* Copy frameworks with Carthage */, ); buildRules = ( ); @@ -375,39 +365,6 @@ }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - D5C629731C3A86E3007F7B7C /* Copy frameworks with Carthage */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "$(SRCROOT)/Carthage/Build/iOS/Sugar.framework", - ); - name = "Copy frameworks with Carthage"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "/usr/local/bin/carthage copy-frameworks"; - }; - D5C629741C3A8717007F7B7C /* Copy frameworks with Carthage */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "$(SRCROOT)/Carthage/Build/Mac/Sugar.framework", - ); - name = "Copy frameworks with Carthage"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "/usr/local/bin/carthage copy-frameworks"; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ D5B2E89A1C3A780C00C0327D /* Sources */ = { isa = PBXSourcesBuildPhase; From 758ac164ff747e0e3535abf7491ff990e08ba092 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 13:52:18 +0200 Subject: [PATCH 06/19] Share compass navigate --- Compass.xcodeproj/project.pbxproj | 20 +++++++++++-------- .../{Mac => Shared}/Compass+Navigate.swift | 3 +-- Sources/Shared/TypeAlias.swift | 19 ++++++++++++++++++ Sources/iOS/Compass+Navigate.swift | 10 ---------- 4 files changed, 32 insertions(+), 20 deletions(-) rename Sources/{Mac => Shared}/Compass+Navigate.swift (79%) create mode 100644 Sources/Shared/TypeAlias.swift delete mode 100644 Sources/iOS/Compass+Navigate.swift diff --git a/Compass.xcodeproj/project.pbxproj b/Compass.xcodeproj/project.pbxproj index 59b2969..564d159 100644 --- a/Compass.xcodeproj/project.pbxproj +++ b/Compass.xcodeproj/project.pbxproj @@ -10,14 +10,16 @@ BD93BC731C4D0CB5006D2D11 /* TestRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD93BC721C4D0CB5006D2D11 /* TestRouter.swift */; }; BDF7B4091C3FF40300576737 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B4081C3FF40300576737 /* Compass.swift */; }; BDF7B40A1C3FF40300576737 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B4081C3FF40300576737 /* Compass.swift */; }; - BDF7B40C1C3FF40A00576737 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40B1C3FF40A00576737 /* Compass+Navigate.swift */; }; - BDF7B40E1C3FF41500576737 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40D1C3FF41500576737 /* Compass+Navigate.swift */; }; BDF7B4101C3FF43F00576737 /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40F1C3FF43F00576737 /* TestCompass.swift */; }; BDF7B4111C3FF43F00576737 /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40F1C3FF43F00576737 /* TestCompass.swift */; }; D20D8C771D0708A800807EB1 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20D8C761D0708A800807EB1 /* Shuffle.swift */; }; D20D8C781D0708A800807EB1 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20D8C761D0708A800807EB1 /* Shuffle.swift */; }; D5361FE11D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */; }; D5361FE21D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */; }; + D5361FE41D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */; }; + D5361FE51D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */; }; + D5361FE71D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */; }; + D5361FE81D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */; }; D5A2A7931C4CEB1C00B51356 /* Routable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A2A7921C4CEB1C00B51356 /* Routable.swift */; }; D5A2A7971C4CEB7C00B51356 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A2A7961C4CEB7C00B51356 /* Router.swift */; }; D5B2E8AA1C3A780C00C0327D /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5B2E89F1C3A780C00C0327D /* Compass.framework */; }; @@ -44,11 +46,11 @@ /* Begin PBXFileReference section */ BD93BC721C4D0CB5006D2D11 /* TestRouter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestRouter.swift; sourceTree = ""; }; BDF7B4081C3FF40300576737 /* Compass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Compass.swift; sourceTree = ""; }; - BDF7B40B1C3FF40A00576737 /* Compass+Navigate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Compass+Navigate.swift"; sourceTree = ""; }; - BDF7B40D1C3FF41500576737 /* Compass+Navigate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Compass+Navigate.swift"; sourceTree = ""; }; BDF7B40F1C3FF43F00576737 /* TestCompass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCompass.swift; sourceTree = ""; }; D20D8C761D0708A800807EB1 /* Shuffle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shuffle.swift; sourceTree = ""; }; D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; + D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = ""; }; + D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Compass+Navigate.swift"; sourceTree = ""; }; D5A2A7921C4CEB1C00B51356 /* Routable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Routable.swift; sourceTree = ""; }; D5A2A7961C4CEB7C00B51356 /* Router.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; D5B2E89F1C3A780C00C0327D /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -139,7 +141,6 @@ isa = PBXGroup; children = ( D5A2A7921C4CEB1C00B51356 /* Routable.swift */, - BDF7B40D1C3FF41500576737 /* Compass+Navigate.swift */, D5A2A7961C4CEB7C00B51356 /* Router.swift */, ); path = iOS; @@ -148,7 +149,6 @@ D5C6296C1C3A809D007F7B7C /* Mac */ = { isa = PBXGroup; children = ( - BDF7B40B1C3FF40A00576737 /* Compass+Navigate.swift */, ); path = Mac; sourceTree = ""; @@ -158,6 +158,8 @@ children = ( BDF7B4081C3FF40300576737 /* Compass.swift */, D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */, + D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */, + D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */, ); path = Shared; sourceTree = ""; @@ -370,11 +372,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D5361FE41D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */, D5361FE11D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */, + D5361FE71D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */, D5A2A7971C4CEB7C00B51356 /* Router.swift in Sources */, BDF7B4091C3FF40300576737 /* Compass.swift in Sources */, D5A2A7931C4CEB1C00B51356 /* Routable.swift in Sources */, - BDF7B40E1C3FF41500576737 /* Compass+Navigate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -394,7 +397,8 @@ files = ( BDF7B40A1C3FF40300576737 /* Compass.swift in Sources */, D5361FE21D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */, - BDF7B40C1C3FF40A00576737 /* Compass+Navigate.swift in Sources */, + D5361FE51D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */, + D5361FE81D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sources/Mac/Compass+Navigate.swift b/Sources/Shared/Compass+Navigate.swift similarity index 79% rename from Sources/Mac/Compass+Navigate.swift rename to Sources/Shared/Compass+Navigate.swift index 87b21fa..b20a161 100644 --- a/Sources/Mac/Compass+Navigate.swift +++ b/Sources/Shared/Compass+Navigate.swift @@ -4,7 +4,6 @@ extension Compass { public static func navigate(urn: String, scheme: String = Compass.scheme) { guard let url = NSURL(string: "\(scheme)\(urn)") else { return } - - NSWorkspace.sharedWorkspace().openURL(url) + openURL(url) } } diff --git a/Sources/Shared/TypeAlias.swift b/Sources/Shared/TypeAlias.swift new file mode 100644 index 0000000..2fcabf7 --- /dev/null +++ b/Sources/Shared/TypeAlias.swift @@ -0,0 +1,19 @@ +#if os(OSX) + import Cocoa +#else + import UIKit +#endif + +#if os(OSX) + public typealias Controller = NSViewController + + func openURL(URL: NSURL) { + NSWorkspace.sharedWorkspace().openURL(URL) + } +#else + public typealias Controller = UIViewController + + func openURL(URL: NSURL) { + UIApplication.sharedApplication().openURL(URL) + } +#endif diff --git a/Sources/iOS/Compass+Navigate.swift b/Sources/iOS/Compass+Navigate.swift deleted file mode 100644 index 11a829e..0000000 --- a/Sources/iOS/Compass+Navigate.swift +++ /dev/null @@ -1,10 +0,0 @@ -import UIKit - -extension Compass { - - public static func navigate(urn: String, scheme: String = Compass.scheme) { - guard let url = NSURL(string: "\(scheme)\(urn)") else { return } - - UIApplication.sharedApplication().openURL(url) - } -} From 8347a0c2bb824558e70930d5b91d046c6da95cd0 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 13:55:03 +0200 Subject: [PATCH 07/19] Share router and routable --- Compass.xcodeproj/project.pbxproj | 30 ++++++------------------------ Sources/Shared/Router.swift | 22 ++++++++++++++++++++++ Sources/iOS/Routable.swift | 6 ------ Sources/iOS/Router.swift | 14 -------------- 4 files changed, 28 insertions(+), 44 deletions(-) create mode 100644 Sources/Shared/Router.swift delete mode 100644 Sources/iOS/Routable.swift delete mode 100644 Sources/iOS/Router.swift diff --git a/Compass.xcodeproj/project.pbxproj b/Compass.xcodeproj/project.pbxproj index 564d159..652ef65 100644 --- a/Compass.xcodeproj/project.pbxproj +++ b/Compass.xcodeproj/project.pbxproj @@ -20,8 +20,8 @@ D5361FE51D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */; }; D5361FE71D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */; }; D5361FE81D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */; }; - D5A2A7931C4CEB1C00B51356 /* Routable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A2A7921C4CEB1C00B51356 /* Routable.swift */; }; - D5A2A7971C4CEB7C00B51356 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A2A7961C4CEB7C00B51356 /* Router.swift */; }; + D5361FED1D6C7090003C3EE8 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FEC1D6C7090003C3EE8 /* Router.swift */; }; + D5361FEE1D6C7090003C3EE8 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FEC1D6C7090003C3EE8 /* Router.swift */; }; D5B2E8AA1C3A780C00C0327D /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5B2E89F1C3A780C00C0327D /* Compass.framework */; }; D5C6294A1C3A7FAA007F7B7C /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5C629401C3A7FAA007F7B7C /* Compass.framework */; }; /* End PBXBuildFile section */ @@ -51,8 +51,7 @@ D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = ""; }; D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Compass+Navigate.swift"; sourceTree = ""; }; - D5A2A7921C4CEB1C00B51356 /* Routable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Routable.swift; sourceTree = ""; }; - D5A2A7961C4CEB7C00B51356 /* Router.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; + D5361FEC1D6C7090003C3EE8 /* Router.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; D5B2E89F1C3A780C00C0327D /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D5B2E8A91C3A780C00C0327D /* Compass-iOS-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Compass-iOS-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; D5C629401C3A7FAA007F7B7C /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -130,29 +129,11 @@ D5C629691C3A809D007F7B7C /* Sources */ = { isa = PBXGroup; children = ( - D5C6296A1C3A809D007F7B7C /* iOS */, - D5C6296C1C3A809D007F7B7C /* Mac */, D5C6296E1C3A809D007F7B7C /* Shared */, ); path = Sources; sourceTree = ""; }; - D5C6296A1C3A809D007F7B7C /* iOS */ = { - isa = PBXGroup; - children = ( - D5A2A7921C4CEB1C00B51356 /* Routable.swift */, - D5A2A7961C4CEB7C00B51356 /* Router.swift */, - ); - path = iOS; - sourceTree = ""; - }; - D5C6296C1C3A809D007F7B7C /* Mac */ = { - isa = PBXGroup; - children = ( - ); - path = Mac; - sourceTree = ""; - }; D5C6296E1C3A809D007F7B7C /* Shared */ = { isa = PBXGroup; children = ( @@ -160,6 +141,7 @@ D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */, D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */, D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */, + D5361FEC1D6C7090003C3EE8 /* Router.swift */, ); path = Shared; sourceTree = ""; @@ -372,12 +354,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D5361FED1D6C7090003C3EE8 /* Router.swift in Sources */, D5361FE41D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */, D5361FE11D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */, D5361FE71D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */, - D5A2A7971C4CEB7C00B51356 /* Router.swift in Sources */, BDF7B4091C3FF40300576737 /* Compass.swift in Sources */, - D5A2A7931C4CEB1C00B51356 /* Routable.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -399,6 +380,7 @@ D5361FE21D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */, D5361FE51D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */, D5361FE81D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */, + D5361FEE1D6C7090003C3EE8 /* Router.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sources/Shared/Router.swift b/Sources/Shared/Router.swift new file mode 100644 index 0000000..4ad5767 --- /dev/null +++ b/Sources/Shared/Router.swift @@ -0,0 +1,22 @@ +public protocol Routable { + + func resolve(arguments: [String: String], + fragments: [String : AnyObject], + currentController: Controller) +} + +public struct Router { + + public var routes = [String: Routable]() + + public init() {} + + public func navigate(route: String, + arguments: [String: String], + fragments: [String : AnyObject] = [:], + from controller: Controller) { + guard let route = routes[route] else { return } + route.resolve(arguments, fragments: fragments, currentController: controller) + } +} + diff --git a/Sources/iOS/Routable.swift b/Sources/iOS/Routable.swift deleted file mode 100644 index 76a8bc0..0000000 --- a/Sources/iOS/Routable.swift +++ /dev/null @@ -1,6 +0,0 @@ -import UIKit - -public protocol Routable { - - func resolve(arguments: [String: String], fragments: [String : AnyObject], currentController: UIViewController) -} diff --git a/Sources/iOS/Router.swift b/Sources/iOS/Router.swift deleted file mode 100644 index b537b93..0000000 --- a/Sources/iOS/Router.swift +++ /dev/null @@ -1,14 +0,0 @@ -import UIKit - -public struct Router { - - public var routes = [String: Routable]() - - public init() {} - - public func navigate(route: String, arguments: [String: String], fragments: [String : AnyObject] = [:], from controller: UIViewController) { - guard let route = routes[route] else { return } - - route.resolve(arguments, fragments: fragments, currentController: controller) - } -} From a23934614a2b432707f28c1bd81b4d1bd6425caf Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 13:55:49 +0200 Subject: [PATCH 08/19] Move files around --- Compass.xcodeproj/project.pbxproj | 70 +++++++++----------- Sources/{Shared => }/Compass+Navigate.swift | 0 Sources/{Shared => }/Compass.swift | 0 Sources/{Shared => }/Router.swift | 0 Sources/{Shared => }/String+Extensions.swift | 0 Sources/{Shared => }/TypeAlias.swift | 0 6 files changed, 31 insertions(+), 39 deletions(-) rename Sources/{Shared => }/Compass+Navigate.swift (100%) rename Sources/{Shared => }/Compass.swift (100%) rename Sources/{Shared => }/Router.swift (100%) rename Sources/{Shared => }/String+Extensions.swift (100%) rename Sources/{Shared => }/TypeAlias.swift (100%) diff --git a/Compass.xcodeproj/project.pbxproj b/Compass.xcodeproj/project.pbxproj index 652ef65..e2b7c5e 100644 --- a/Compass.xcodeproj/project.pbxproj +++ b/Compass.xcodeproj/project.pbxproj @@ -8,20 +8,20 @@ /* Begin PBXBuildFile section */ BD93BC731C4D0CB5006D2D11 /* TestRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD93BC721C4D0CB5006D2D11 /* TestRouter.swift */; }; - BDF7B4091C3FF40300576737 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B4081C3FF40300576737 /* Compass.swift */; }; - BDF7B40A1C3FF40300576737 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B4081C3FF40300576737 /* Compass.swift */; }; BDF7B4101C3FF43F00576737 /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40F1C3FF43F00576737 /* TestCompass.swift */; }; BDF7B4111C3FF43F00576737 /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40F1C3FF43F00576737 /* TestCompass.swift */; }; D20D8C771D0708A800807EB1 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20D8C761D0708A800807EB1 /* Shuffle.swift */; }; D20D8C781D0708A800807EB1 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20D8C761D0708A800807EB1 /* Shuffle.swift */; }; - D5361FE11D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */; }; - D5361FE21D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */; }; - D5361FE41D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */; }; - D5361FE51D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */; }; - D5361FE71D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */; }; - D5361FE81D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */; }; - D5361FED1D6C7090003C3EE8 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FEC1D6C7090003C3EE8 /* Router.swift */; }; - D5361FEE1D6C7090003C3EE8 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FEC1D6C7090003C3EE8 /* Router.swift */; }; + D5361FF41D6C7133003C3EE8 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FEF1D6C7133003C3EE8 /* Router.swift */; }; + D5361FF51D6C7133003C3EE8 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FEF1D6C7133003C3EE8 /* Router.swift */; }; + D5361FF61D6C7133003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF01D6C7133003C3EE8 /* Compass+Navigate.swift */; }; + D5361FF71D6C7133003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF01D6C7133003C3EE8 /* Compass+Navigate.swift */; }; + D5361FF81D6C7133003C3EE8 /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF11D6C7133003C3EE8 /* TypeAlias.swift */; }; + D5361FF91D6C7133003C3EE8 /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF11D6C7133003C3EE8 /* TypeAlias.swift */; }; + D5361FFA1D6C7133003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */; }; + D5361FFB1D6C7133003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */; }; + D5361FFC1D6C7133003C3EE8 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF31D6C7133003C3EE8 /* Compass.swift */; }; + D5361FFD1D6C7133003C3EE8 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF31D6C7133003C3EE8 /* Compass.swift */; }; D5B2E8AA1C3A780C00C0327D /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5B2E89F1C3A780C00C0327D /* Compass.framework */; }; D5C6294A1C3A7FAA007F7B7C /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5C629401C3A7FAA007F7B7C /* Compass.framework */; }; /* End PBXBuildFile section */ @@ -45,13 +45,13 @@ /* Begin PBXFileReference section */ BD93BC721C4D0CB5006D2D11 /* TestRouter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestRouter.swift; sourceTree = ""; }; - BDF7B4081C3FF40300576737 /* Compass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Compass.swift; sourceTree = ""; }; BDF7B40F1C3FF43F00576737 /* TestCompass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCompass.swift; sourceTree = ""; }; D20D8C761D0708A800807EB1 /* Shuffle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shuffle.swift; sourceTree = ""; }; - D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; - D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = ""; }; - D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Compass+Navigate.swift"; sourceTree = ""; }; - D5361FEC1D6C7090003C3EE8 /* Router.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; + D5361FEF1D6C7133003C3EE8 /* Router.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; + D5361FF01D6C7133003C3EE8 /* Compass+Navigate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Compass+Navigate.swift"; sourceTree = ""; }; + D5361FF11D6C7133003C3EE8 /* TypeAlias.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = ""; }; + D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; + D5361FF31D6C7133003C3EE8 /* Compass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Compass.swift; sourceTree = ""; }; D5B2E89F1C3A780C00C0327D /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D5B2E8A91C3A780C00C0327D /* Compass-iOS-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Compass-iOS-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; D5C629401C3A7FAA007F7B7C /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -129,23 +129,15 @@ D5C629691C3A809D007F7B7C /* Sources */ = { isa = PBXGroup; children = ( - D5C6296E1C3A809D007F7B7C /* Shared */, + D5361FEF1D6C7133003C3EE8 /* Router.swift */, + D5361FF01D6C7133003C3EE8 /* Compass+Navigate.swift */, + D5361FF11D6C7133003C3EE8 /* TypeAlias.swift */, + D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */, + D5361FF31D6C7133003C3EE8 /* Compass.swift */, ); path = Sources; sourceTree = ""; }; - D5C6296E1C3A809D007F7B7C /* Shared */ = { - isa = PBXGroup; - children = ( - BDF7B4081C3FF40300576737 /* Compass.swift */, - D5361FE01D6C6B7B003C3EE8 /* String+Extensions.swift */, - D5361FE31D6C6F1E003C3EE8 /* TypeAlias.swift */, - D5361FE61D6C7037003C3EE8 /* Compass+Navigate.swift */, - D5361FEC1D6C7090003C3EE8 /* Router.swift */, - ); - path = Shared; - sourceTree = ""; - }; D5C6298F1C3A8BDA007F7B7C /* CompassTests */ = { isa = PBXGroup; children = ( @@ -280,7 +272,7 @@ D5B2E8961C3A780C00C0327D /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 0720; + LastSwiftUpdateCheck = 0730; LastUpgradeCheck = 0720; ORGANIZATIONNAME = "Hyper Interaktiv AS"; TargetAttributes = { @@ -354,11 +346,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - D5361FED1D6C7090003C3EE8 /* Router.swift in Sources */, - D5361FE41D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */, - D5361FE11D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */, - D5361FE71D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */, - BDF7B4091C3FF40300576737 /* Compass.swift in Sources */, + D5361FFC1D6C7133003C3EE8 /* Compass.swift in Sources */, + D5361FFA1D6C7133003C3EE8 /* String+Extensions.swift in Sources */, + D5361FF81D6C7133003C3EE8 /* TypeAlias.swift in Sources */, + D5361FF41D6C7133003C3EE8 /* Router.swift in Sources */, + D5361FF61D6C7133003C3EE8 /* Compass+Navigate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -376,11 +368,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - BDF7B40A1C3FF40300576737 /* Compass.swift in Sources */, - D5361FE21D6C6B7B003C3EE8 /* String+Extensions.swift in Sources */, - D5361FE51D6C6F1E003C3EE8 /* TypeAlias.swift in Sources */, - D5361FE81D6C7037003C3EE8 /* Compass+Navigate.swift in Sources */, - D5361FEE1D6C7090003C3EE8 /* Router.swift in Sources */, + D5361FFD1D6C7133003C3EE8 /* Compass.swift in Sources */, + D5361FFB1D6C7133003C3EE8 /* String+Extensions.swift in Sources */, + D5361FF91D6C7133003C3EE8 /* TypeAlias.swift in Sources */, + D5361FF51D6C7133003C3EE8 /* Router.swift in Sources */, + D5361FF71D6C7133003C3EE8 /* Compass+Navigate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sources/Shared/Compass+Navigate.swift b/Sources/Compass+Navigate.swift similarity index 100% rename from Sources/Shared/Compass+Navigate.swift rename to Sources/Compass+Navigate.swift diff --git a/Sources/Shared/Compass.swift b/Sources/Compass.swift similarity index 100% rename from Sources/Shared/Compass.swift rename to Sources/Compass.swift diff --git a/Sources/Shared/Router.swift b/Sources/Router.swift similarity index 100% rename from Sources/Shared/Router.swift rename to Sources/Router.swift diff --git a/Sources/Shared/String+Extensions.swift b/Sources/String+Extensions.swift similarity index 100% rename from Sources/Shared/String+Extensions.swift rename to Sources/String+Extensions.swift diff --git a/Sources/Shared/TypeAlias.swift b/Sources/TypeAlias.swift similarity index 100% rename from Sources/Shared/TypeAlias.swift rename to Sources/TypeAlias.swift From ff13057b5bb28ff005589d393f2d0f3a24c5d6c0 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 14:00:37 +0200 Subject: [PATCH 09/19] Refactor tests --- Compass.xcodeproj/project.pbxproj | 58 ++++++------------- .../TestCompass.swift => CompassTests.swift} | 2 +- .../TestRouter.swift => RouterTests.swift} | 6 +- CompassTests/{Shared => }/Shuffle.swift | 0 Sources/Compass+Navigate.swift | 2 +- 5 files changed, 23 insertions(+), 45 deletions(-) rename CompassTests/{Shared/TestCompass.swift => CompassTests.swift} (99%) rename CompassTests/{iOS/TestRouter.swift => RouterTests.swift} (82%) rename CompassTests/{Shared => }/Shuffle.swift (100%) diff --git a/Compass.xcodeproj/project.pbxproj b/Compass.xcodeproj/project.pbxproj index e2b7c5e..764fa10 100644 --- a/Compass.xcodeproj/project.pbxproj +++ b/Compass.xcodeproj/project.pbxproj @@ -7,11 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - BD93BC731C4D0CB5006D2D11 /* TestRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD93BC721C4D0CB5006D2D11 /* TestRouter.swift */; }; - BDF7B4101C3FF43F00576737 /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40F1C3FF43F00576737 /* TestCompass.swift */; }; - BDF7B4111C3FF43F00576737 /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF7B40F1C3FF43F00576737 /* TestCompass.swift */; }; - D20D8C771D0708A800807EB1 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20D8C761D0708A800807EB1 /* Shuffle.swift */; }; - D20D8C781D0708A800807EB1 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20D8C761D0708A800807EB1 /* Shuffle.swift */; }; D5361FF41D6C7133003C3EE8 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FEF1D6C7133003C3EE8 /* Router.swift */; }; D5361FF51D6C7133003C3EE8 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FEF1D6C7133003C3EE8 /* Router.swift */; }; D5361FF61D6C7133003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF01D6C7133003C3EE8 /* Compass+Navigate.swift */; }; @@ -22,6 +17,12 @@ D5361FFB1D6C7133003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */; }; D5361FFC1D6C7133003C3EE8 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF31D6C7133003C3EE8 /* Compass.swift */; }; D5361FFD1D6C7133003C3EE8 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF31D6C7133003C3EE8 /* Compass.swift */; }; + D53620071D6C7189003C3EE8 /* CompassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FFE1D6C7181003C3EE8 /* CompassTests.swift */; }; + D53620081D6C7189003C3EE8 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FFF1D6C7181003C3EE8 /* Shuffle.swift */; }; + D53620091D6C7189003C3EE8 /* RouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53620001D6C7181003C3EE8 /* RouterTests.swift */; }; + D536200A1D6C718A003C3EE8 /* CompassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FFE1D6C7181003C3EE8 /* CompassTests.swift */; }; + D536200B1D6C718A003C3EE8 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FFF1D6C7181003C3EE8 /* Shuffle.swift */; }; + D536200C1D6C718A003C3EE8 /* RouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53620001D6C7181003C3EE8 /* RouterTests.swift */; }; D5B2E8AA1C3A780C00C0327D /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5B2E89F1C3A780C00C0327D /* Compass.framework */; }; D5C6294A1C3A7FAA007F7B7C /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5C629401C3A7FAA007F7B7C /* Compass.framework */; }; /* End PBXBuildFile section */ @@ -44,14 +45,14 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - BD93BC721C4D0CB5006D2D11 /* TestRouter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestRouter.swift; sourceTree = ""; }; - BDF7B40F1C3FF43F00576737 /* TestCompass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCompass.swift; sourceTree = ""; }; - D20D8C761D0708A800807EB1 /* Shuffle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shuffle.swift; sourceTree = ""; }; D5361FEF1D6C7133003C3EE8 /* Router.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; D5361FF01D6C7133003C3EE8 /* Compass+Navigate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Compass+Navigate.swift"; sourceTree = ""; }; D5361FF11D6C7133003C3EE8 /* TypeAlias.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = ""; }; D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; D5361FF31D6C7133003C3EE8 /* Compass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Compass.swift; sourceTree = ""; }; + D5361FFE1D6C7181003C3EE8 /* CompassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompassTests.swift; sourceTree = ""; }; + D5361FFF1D6C7181003C3EE8 /* Shuffle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shuffle.swift; sourceTree = ""; }; + D53620001D6C7181003C3EE8 /* RouterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RouterTests.swift; sourceTree = ""; }; D5B2E89F1C3A780C00C0327D /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D5B2E8A91C3A780C00C0327D /* Compass-iOS-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Compass-iOS-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; D5C629401C3A7FAA007F7B7C /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -141,39 +142,15 @@ D5C6298F1C3A8BDA007F7B7C /* CompassTests */ = { isa = PBXGroup; children = ( + D5361FFE1D6C7181003C3EE8 /* CompassTests.swift */, + D5361FFF1D6C7181003C3EE8 /* Shuffle.swift */, + D53620001D6C7181003C3EE8 /* RouterTests.swift */, D5C629901C3A8BDA007F7B7C /* Info-iOS.plist */, D5C629911C3A8BDA007F7B7C /* Info-Mac.plist */, - D5C629921C3A8BDA007F7B7C /* iOS */, - D5C629941C3A8BDA007F7B7C /* Mac */, - D5C629961C3A8BDA007F7B7C /* Shared */, ); path = CompassTests; sourceTree = ""; }; - D5C629921C3A8BDA007F7B7C /* iOS */ = { - isa = PBXGroup; - children = ( - BD93BC721C4D0CB5006D2D11 /* TestRouter.swift */, - ); - path = iOS; - sourceTree = ""; - }; - D5C629941C3A8BDA007F7B7C /* Mac */ = { - isa = PBXGroup; - children = ( - ); - path = Mac; - sourceTree = ""; - }; - D5C629961C3A8BDA007F7B7C /* Shared */ = { - isa = PBXGroup; - children = ( - BDF7B40F1C3FF43F00576737 /* TestCompass.swift */, - D20D8C761D0708A800807EB1 /* Shuffle.swift */, - ); - path = Shared; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -358,9 +335,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - BD93BC731C4D0CB5006D2D11 /* TestRouter.swift in Sources */, - D20D8C771D0708A800807EB1 /* Shuffle.swift in Sources */, - BDF7B4101C3FF43F00576737 /* TestCompass.swift in Sources */, + D53620071D6C7189003C3EE8 /* CompassTests.swift in Sources */, + D53620081D6C7189003C3EE8 /* Shuffle.swift in Sources */, + D53620091D6C7189003C3EE8 /* RouterTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -380,8 +357,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - BDF7B4111C3FF43F00576737 /* TestCompass.swift in Sources */, - D20D8C781D0708A800807EB1 /* Shuffle.swift in Sources */, + D536200A1D6C718A003C3EE8 /* CompassTests.swift in Sources */, + D536200B1D6C718A003C3EE8 /* Shuffle.swift in Sources */, + D536200C1D6C718A003C3EE8 /* RouterTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/CompassTests/Shared/TestCompass.swift b/CompassTests/CompassTests.swift similarity index 99% rename from CompassTests/Shared/TestCompass.swift rename to CompassTests/CompassTests.swift index 8df424f..33e8d77 100644 --- a/CompassTests/Shared/TestCompass.swift +++ b/CompassTests/CompassTests.swift @@ -2,7 +2,7 @@ import Foundation import XCTest import Compass -class TestCompass: XCTestCase { +class CompassTests: XCTestCase { override func setUp() { Compass.scheme = "compassTests" diff --git a/CompassTests/iOS/TestRouter.swift b/CompassTests/RouterTests.swift similarity index 82% rename from CompassTests/iOS/TestRouter.swift rename to CompassTests/RouterTests.swift index fdbc347..c8cead5 100644 --- a/CompassTests/iOS/TestRouter.swift +++ b/CompassTests/RouterTests.swift @@ -6,15 +6,15 @@ class TestRoute: Routable { var resolved = false - func resolve(arguments: [String: String], fragments: [String : AnyObject] = [:], currentController controller: UIViewController) { + func resolve(arguments: [String: String], fragments: [String : AnyObject] = [:], currentController controller: Controller) { resolved = true } } -class TestRouter: XCTestCase { +class RouterTests: XCTestCase { var router: Router! - var controller = UIViewController() + var controller = Controller() var route: TestRoute! override func setUp() { diff --git a/CompassTests/Shared/Shuffle.swift b/CompassTests/Shuffle.swift similarity index 100% rename from CompassTests/Shared/Shuffle.swift rename to CompassTests/Shuffle.swift diff --git a/Sources/Compass+Navigate.swift b/Sources/Compass+Navigate.swift index b20a161..89afba4 100644 --- a/Sources/Compass+Navigate.swift +++ b/Sources/Compass+Navigate.swift @@ -1,4 +1,4 @@ -import Cocoa +import Foundation extension Compass { From 7dd67793c66a14665a6d8a63cdcbbc46026234c1 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 14:13:50 +0200 Subject: [PATCH 10/19] Re-structure project --- Cartfile | 1 - Cartfile.resolved | 1 - Compass.xcodeproj/project.pbxproj | 148 ++++++++---------- {Compass => Project}/Info-Mac.plist | 0 .../Info-Tests-Mac.plist | 0 .../Info-Tests-iOS.plist | 0 {Compass => Project}/Info-iOS.plist | 0 .../Compass}/CompassTests.swift | 0 .../Compass/Helpers.swift | 14 ++ .../Compass}/RouterTests.swift | 11 +- 10 files changed, 81 insertions(+), 94 deletions(-) delete mode 100644 Cartfile delete mode 100644 Cartfile.resolved rename {Compass => Project}/Info-Mac.plist (100%) rename CompassTests/Info-Mac.plist => Project/Info-Tests-Mac.plist (100%) rename CompassTests/Info-iOS.plist => Project/Info-Tests-iOS.plist (100%) rename {Compass => Project}/Info-iOS.plist (100%) rename {CompassTests => Tests/Compass}/CompassTests.swift (100%) rename CompassTests/Shuffle.swift => Tests/Compass/Helpers.swift (71%) rename {CompassTests => Tests/Compass}/RouterTests.swift (71%) diff --git a/Cartfile b/Cartfile deleted file mode 100644 index 324ff66..0000000 --- a/Cartfile +++ /dev/null @@ -1 +0,0 @@ -github "hyperoslo/Sugar" diff --git a/Cartfile.resolved b/Cartfile.resolved deleted file mode 100644 index 8850d21..0000000 --- a/Cartfile.resolved +++ /dev/null @@ -1 +0,0 @@ -github "hyperoslo/Sugar" "1.1.1" diff --git a/Compass.xcodeproj/project.pbxproj b/Compass.xcodeproj/project.pbxproj index 764fa10..983bdef 100644 --- a/Compass.xcodeproj/project.pbxproj +++ b/Compass.xcodeproj/project.pbxproj @@ -17,12 +17,12 @@ D5361FFB1D6C7133003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */; }; D5361FFC1D6C7133003C3EE8 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF31D6C7133003C3EE8 /* Compass.swift */; }; D5361FFD1D6C7133003C3EE8 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF31D6C7133003C3EE8 /* Compass.swift */; }; - D53620071D6C7189003C3EE8 /* CompassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FFE1D6C7181003C3EE8 /* CompassTests.swift */; }; - D53620081D6C7189003C3EE8 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FFF1D6C7181003C3EE8 /* Shuffle.swift */; }; - D53620091D6C7189003C3EE8 /* RouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53620001D6C7181003C3EE8 /* RouterTests.swift */; }; - D536200A1D6C718A003C3EE8 /* CompassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FFE1D6C7181003C3EE8 /* CompassTests.swift */; }; - D536200B1D6C718A003C3EE8 /* Shuffle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FFF1D6C7181003C3EE8 /* Shuffle.swift */; }; - D536200C1D6C718A003C3EE8 /* RouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53620001D6C7181003C3EE8 /* RouterTests.swift */; }; + D53620251D6C749A003C3EE8 /* CompassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D536200F1D6C743A003C3EE8 /* CompassTests.swift */; }; + D53620261D6C749A003C3EE8 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53620101D6C743A003C3EE8 /* Helpers.swift */; }; + D53620271D6C749A003C3EE8 /* RouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53620111D6C743A003C3EE8 /* RouterTests.swift */; }; + D53620281D6C749B003C3EE8 /* CompassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D536200F1D6C743A003C3EE8 /* CompassTests.swift */; }; + D53620291D6C749B003C3EE8 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53620101D6C743A003C3EE8 /* Helpers.swift */; }; + D536202A1D6C749B003C3EE8 /* RouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53620111D6C743A003C3EE8 /* RouterTests.swift */; }; D5B2E8AA1C3A780C00C0327D /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5B2E89F1C3A780C00C0327D /* Compass.framework */; }; D5C6294A1C3A7FAA007F7B7C /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5C629401C3A7FAA007F7B7C /* Compass.framework */; }; /* End PBXBuildFile section */ @@ -50,17 +50,17 @@ D5361FF11D6C7133003C3EE8 /* TypeAlias.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = ""; }; D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; D5361FF31D6C7133003C3EE8 /* Compass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Compass.swift; sourceTree = ""; }; - D5361FFE1D6C7181003C3EE8 /* CompassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompassTests.swift; sourceTree = ""; }; - D5361FFF1D6C7181003C3EE8 /* Shuffle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shuffle.swift; sourceTree = ""; }; - D53620001D6C7181003C3EE8 /* RouterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RouterTests.swift; sourceTree = ""; }; + D536200F1D6C743A003C3EE8 /* CompassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompassTests.swift; sourceTree = ""; }; + D53620101D6C743A003C3EE8 /* Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = ""; }; + D53620111D6C743A003C3EE8 /* RouterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RouterTests.swift; sourceTree = ""; }; + D53620131D6C743A003C3EE8 /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; + D53620141D6C743A003C3EE8 /* Info-Mac.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Mac.plist"; sourceTree = ""; }; + D53620151D6C743A003C3EE8 /* Info-Tests-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Tests-iOS.plist"; sourceTree = ""; }; + D53620161D6C743A003C3EE8 /* Info-Tests-Mac.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Tests-Mac.plist"; sourceTree = ""; }; D5B2E89F1C3A780C00C0327D /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D5B2E8A91C3A780C00C0327D /* Compass-iOS-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Compass-iOS-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; D5C629401C3A7FAA007F7B7C /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D5C629491C3A7FAA007F7B7C /* Compass-Mac-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Compass-Mac-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - D5C6298B1C3A8BBD007F7B7C /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; - D5C6298C1C3A8BBD007F7B7C /* Info-Mac.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Mac.plist"; sourceTree = ""; }; - D5C629901C3A8BDA007F7B7C /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; - D5C629911C3A8BDA007F7B7C /* Info-Mac.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Mac.plist"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -97,12 +97,41 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + D536200D1D6C743A003C3EE8 /* Tests */ = { + isa = PBXGroup; + children = ( + D536200E1D6C743A003C3EE8 /* Compass */, + ); + path = Tests; + sourceTree = ""; + }; + D536200E1D6C743A003C3EE8 /* Compass */ = { + isa = PBXGroup; + children = ( + D536200F1D6C743A003C3EE8 /* CompassTests.swift */, + D53620101D6C743A003C3EE8 /* Helpers.swift */, + D53620111D6C743A003C3EE8 /* RouterTests.swift */, + ); + path = Compass; + sourceTree = ""; + }; + D53620121D6C743A003C3EE8 /* Project */ = { + isa = PBXGroup; + children = ( + D53620131D6C743A003C3EE8 /* Info-iOS.plist */, + D53620141D6C743A003C3EE8 /* Info-Mac.plist */, + D53620151D6C743A003C3EE8 /* Info-Tests-iOS.plist */, + D53620161D6C743A003C3EE8 /* Info-Tests-Mac.plist */, + ); + path = Project; + sourceTree = ""; + }; D5B2E8951C3A780C00C0327D = { isa = PBXGroup; children = ( + D53620121D6C743A003C3EE8 /* Project */, D5C629691C3A809D007F7B7C /* Sources */, - D5C6295C1C3A800E007F7B7C /* Compass */, - D5C6298F1C3A8BDA007F7B7C /* CompassTests */, + D536200D1D6C743A003C3EE8 /* Tests */, D5B2E8A01C3A780C00C0327D /* Products */, ); sourceTree = ""; @@ -118,15 +147,6 @@ name = Products; sourceTree = ""; }; - D5C6295C1C3A800E007F7B7C /* Compass */ = { - isa = PBXGroup; - children = ( - D5C6298B1C3A8BBD007F7B7C /* Info-iOS.plist */, - D5C6298C1C3A8BBD007F7B7C /* Info-Mac.plist */, - ); - path = Compass; - sourceTree = ""; - }; D5C629691C3A809D007F7B7C /* Sources */ = { isa = PBXGroup; children = ( @@ -139,18 +159,6 @@ path = Sources; sourceTree = ""; }; - D5C6298F1C3A8BDA007F7B7C /* CompassTests */ = { - isa = PBXGroup; - children = ( - D5361FFE1D6C7181003C3EE8 /* CompassTests.swift */, - D5361FFF1D6C7181003C3EE8 /* Shuffle.swift */, - D53620001D6C7181003C3EE8 /* RouterTests.swift */, - D5C629901C3A8BDA007F7B7C /* Info-iOS.plist */, - D5C629911C3A8BDA007F7B7C /* Info-Mac.plist */, - ); - path = CompassTests; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -335,9 +343,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - D53620071D6C7189003C3EE8 /* CompassTests.swift in Sources */, - D53620081D6C7189003C3EE8 /* Shuffle.swift in Sources */, - D53620091D6C7189003C3EE8 /* RouterTests.swift in Sources */, + D53620251D6C749A003C3EE8 /* CompassTests.swift in Sources */, + D53620271D6C749A003C3EE8 /* RouterTests.swift in Sources */, + D53620261D6C749A003C3EE8 /* Helpers.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -357,9 +365,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - D536200A1D6C718A003C3EE8 /* CompassTests.swift in Sources */, - D536200B1D6C718A003C3EE8 /* Shuffle.swift in Sources */, - D536200C1D6C718A003C3EE8 /* RouterTests.swift in Sources */, + D53620281D6C749B003C3EE8 /* CompassTests.swift in Sources */, + D536202A1D6C749B003C3EE8 /* RouterTests.swift in Sources */, + D53620291D6C749B003C3EE8 /* Helpers.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -478,11 +486,8 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); - INFOPLIST_FILE = "$(SRCROOT)/Compass/Info-iOS.plist"; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = "$(SRCROOT)/Project/Info-iOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -501,11 +506,8 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); - INFOPLIST_FILE = "$(SRCROOT)/Compass/Info-iOS.plist"; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = "$(SRCROOT)/Project/Info-iOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -519,11 +521,8 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); - INFOPLIST_FILE = "$(SRCROOT)/CompassTests/Info-iOS.plist"; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = "$(SRCROOT)/Project/Info-Tests-iOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = no.hyper.CompassTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -535,11 +534,8 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); - INFOPLIST_FILE = "$(SRCROOT)/CompassTests/Info-iOS.plist"; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = "$(SRCROOT)/Project/Info-Tests-iOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = no.hyper.CompassTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -556,12 +552,9 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/Mac", - ); + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; FRAMEWORK_VERSION = A; - INFOPLIST_FILE = "$(SRCROOT)/Compass/Info-Mac.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Project/Info-Mac.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -583,12 +576,9 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/Mac", - ); + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; FRAMEWORK_VERSION = A; - INFOPLIST_FILE = "$(SRCROOT)/Compass/Info-Mac.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Project/Info-Mac.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -604,11 +594,8 @@ buildSettings = { CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/Mac", - ); - INFOPLIST_FILE = "$(SRCROOT)/CompassTests/Info-Mac.plist"; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = "$(SRCROOT)/Project/Info-Tests-Mac.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.Compass-MacTests"; @@ -622,11 +609,8 @@ buildSettings = { CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/Mac", - ); - INFOPLIST_FILE = "$(SRCROOT)/CompassTests/Info-Mac.plist"; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = "$(SRCROOT)/Project/Info-Tests-Mac.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.Compass-MacTests"; diff --git a/Compass/Info-Mac.plist b/Project/Info-Mac.plist similarity index 100% rename from Compass/Info-Mac.plist rename to Project/Info-Mac.plist diff --git a/CompassTests/Info-Mac.plist b/Project/Info-Tests-Mac.plist similarity index 100% rename from CompassTests/Info-Mac.plist rename to Project/Info-Tests-Mac.plist diff --git a/CompassTests/Info-iOS.plist b/Project/Info-Tests-iOS.plist similarity index 100% rename from CompassTests/Info-iOS.plist rename to Project/Info-Tests-iOS.plist diff --git a/Compass/Info-iOS.plist b/Project/Info-iOS.plist similarity index 100% rename from Compass/Info-iOS.plist rename to Project/Info-iOS.plist diff --git a/CompassTests/CompassTests.swift b/Tests/Compass/CompassTests.swift similarity index 100% rename from CompassTests/CompassTests.swift rename to Tests/Compass/CompassTests.swift diff --git a/CompassTests/Shuffle.swift b/Tests/Compass/Helpers.swift similarity index 71% rename from CompassTests/Shuffle.swift rename to Tests/Compass/Helpers.swift index d6178fd..80e24b3 100644 --- a/CompassTests/Shuffle.swift +++ b/Tests/Compass/Helpers.swift @@ -1,4 +1,18 @@ import Foundation +@testable import Compass + +// MARK: - Routes + +class TestRoute: Routable { + + var resolved = false + + func resolve(arguments: [String: String], fragments: [String : AnyObject] = [:], currentController controller: Controller) { + resolved = true + } +} + +// MARK: - Shuffle extension CollectionType { /// Return a copy of `self` with its elements shuffled diff --git a/CompassTests/RouterTests.swift b/Tests/Compass/RouterTests.swift similarity index 71% rename from CompassTests/RouterTests.swift rename to Tests/Compass/RouterTests.swift index c8cead5..30b421e 100644 --- a/CompassTests/RouterTests.swift +++ b/Tests/Compass/RouterTests.swift @@ -1,15 +1,6 @@ import Foundation import XCTest -import Compass - -class TestRoute: Routable { - - var resolved = false - - func resolve(arguments: [String: String], fragments: [String : AnyObject] = [:], currentController controller: Controller) { - resolved = true - } -} +@testable import Compass class RouterTests: XCTestCase { From f1bfccb6d67ef7260b9ba8119cb7a2123b7f1103 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 14:20:40 +0200 Subject: [PATCH 11/19] Rename to identifier --- Sources/Compass.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Compass.swift b/Sources/Compass.swift index 344391e..29e6695 100644 --- a/Sources/Compass.swift +++ b/Sources/Compass.swift @@ -2,7 +2,7 @@ import Foundation public struct Route { - public let route: String + public let identifier: String public let arguments: [String: String] public let fragments: [String: AnyObject] } @@ -42,7 +42,7 @@ public struct Compass { } if let result = results.first { - return Route(route: result.route, arguments: result.arguments, fragments: fragments) + return Route(identifier: result.route, arguments: result.arguments, fragments: fragments) } return nil @@ -63,7 +63,7 @@ public struct Compass { arguments = fragment.queryParameters() } - return Route(route: route, arguments: arguments, fragments: fragments) + return Route(identifier: route, arguments: arguments, fragments: fragments) } static func findMatch(routeString: String, pathString: String) From 5c0b57e8880443b2a43ff577469ea3be5ee8544d Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 15:18:20 +0200 Subject: [PATCH 12/19] Rename to location --- Sources/Compass.swift | 16 ++++++++++------ Sources/Router.swift | 15 +++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Sources/Compass.swift b/Sources/Compass.swift index 29e6695..52f94f9 100644 --- a/Sources/Compass.swift +++ b/Sources/Compass.swift @@ -1,10 +1,14 @@ import Foundation -public struct Route { +public struct Location { - public let identifier: String + public let path: String public let arguments: [String: String] public let fragments: [String: AnyObject] + + public var scheme: String { + return Compass.scheme + } } public struct Compass { @@ -23,7 +27,7 @@ public struct Compass { public static var routes = [String]() - public static func parse(url: NSURL, fragments: [String : AnyObject] = [:]) -> Route? { + public static func parse(url: NSURL, fragments: [String : AnyObject] = [:]) -> Location? { let path = url.absoluteString.substringFromIndex(scheme.endIndex) @@ -42,13 +46,13 @@ public struct Compass { } if let result = results.first { - return Route(identifier: result.route, arguments: result.arguments, fragments: fragments) + return Location(path: result.route, arguments: result.arguments, fragments: fragments) } return nil } - static func parseAsURL(url: NSURL, fragments: [String : AnyObject] = [:]) -> Route? { + static func parseAsURL(url: NSURL, fragments: [String : AnyObject] = [:]) -> Location? { guard let route = url.host else { return nil } let urlComponents = NSURLComponents(URL: url, resolvingAgainstBaseURL: false) @@ -63,7 +67,7 @@ public struct Compass { arguments = fragment.queryParameters() } - return Route(identifier: route, arguments: arguments, fragments: fragments) + return Location(path: route, arguments: arguments, fragments: fragments) } static func findMatch(routeString: String, pathString: String) diff --git a/Sources/Router.swift b/Sources/Router.swift index 4ad5767..716fa3c 100644 --- a/Sources/Router.swift +++ b/Sources/Router.swift @@ -1,22 +1,17 @@ public protocol Routable { - func resolve(arguments: [String: String], - fragments: [String : AnyObject], - currentController: Controller) + func navigate(to location: Location, from currentController: Controller) } -public struct Router { +public struct Router: Routable { public var routes = [String: Routable]() public init() {} - public func navigate(route: String, - arguments: [String: String], - fragments: [String : AnyObject] = [:], - from controller: Controller) { - guard let route = routes[route] else { return } - route.resolve(arguments, fragments: fragments, currentController: controller) + public func navigate(to location: Location, from currentController: Controller) { + guard let route = routes[location.path] else { return } + route.navigate(to: location, from: currentController) } } From c1bdcd67abfcbd017aaae7655a8e90eeb6f36bef Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 15:22:16 +0200 Subject: [PATCH 13/19] Move files around again --- Compass.xcodeproj/project.pbxproj | 12 +++--- Sources/Compass+Navigate.swift | 9 ----- Sources/Compass.swift | 65 ++++++++++--------------------- Sources/Location.swift | 16 ++++++++ Sources/String+Extensions.swift | 20 ++++++++++ 5 files changed, 62 insertions(+), 60 deletions(-) delete mode 100644 Sources/Compass+Navigate.swift create mode 100644 Sources/Location.swift diff --git a/Compass.xcodeproj/project.pbxproj b/Compass.xcodeproj/project.pbxproj index 983bdef..cd7a1c6 100644 --- a/Compass.xcodeproj/project.pbxproj +++ b/Compass.xcodeproj/project.pbxproj @@ -9,8 +9,6 @@ /* Begin PBXBuildFile section */ D5361FF41D6C7133003C3EE8 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FEF1D6C7133003C3EE8 /* Router.swift */; }; D5361FF51D6C7133003C3EE8 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FEF1D6C7133003C3EE8 /* Router.swift */; }; - D5361FF61D6C7133003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF01D6C7133003C3EE8 /* Compass+Navigate.swift */; }; - D5361FF71D6C7133003C3EE8 /* Compass+Navigate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF01D6C7133003C3EE8 /* Compass+Navigate.swift */; }; D5361FF81D6C7133003C3EE8 /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF11D6C7133003C3EE8 /* TypeAlias.swift */; }; D5361FF91D6C7133003C3EE8 /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF11D6C7133003C3EE8 /* TypeAlias.swift */; }; D5361FFA1D6C7133003C3EE8 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */; }; @@ -23,6 +21,8 @@ D53620281D6C749B003C3EE8 /* CompassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D536200F1D6C743A003C3EE8 /* CompassTests.swift */; }; D53620291D6C749B003C3EE8 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53620101D6C743A003C3EE8 /* Helpers.swift */; }; D536202A1D6C749B003C3EE8 /* RouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53620111D6C743A003C3EE8 /* RouterTests.swift */; }; + D536202C1D6C8532003C3EE8 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = D536202B1D6C8532003C3EE8 /* Location.swift */; }; + D536202D1D6C8532003C3EE8 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = D536202B1D6C8532003C3EE8 /* Location.swift */; }; D5B2E8AA1C3A780C00C0327D /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5B2E89F1C3A780C00C0327D /* Compass.framework */; }; D5C6294A1C3A7FAA007F7B7C /* Compass.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5C629401C3A7FAA007F7B7C /* Compass.framework */; }; /* End PBXBuildFile section */ @@ -46,7 +46,6 @@ /* Begin PBXFileReference section */ D5361FEF1D6C7133003C3EE8 /* Router.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; - D5361FF01D6C7133003C3EE8 /* Compass+Navigate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Compass+Navigate.swift"; sourceTree = ""; }; D5361FF11D6C7133003C3EE8 /* TypeAlias.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = ""; }; D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; D5361FF31D6C7133003C3EE8 /* Compass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Compass.swift; sourceTree = ""; }; @@ -57,6 +56,7 @@ D53620141D6C743A003C3EE8 /* Info-Mac.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Mac.plist"; sourceTree = ""; }; D53620151D6C743A003C3EE8 /* Info-Tests-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Tests-iOS.plist"; sourceTree = ""; }; D53620161D6C743A003C3EE8 /* Info-Tests-Mac.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Tests-Mac.plist"; sourceTree = ""; }; + D536202B1D6C8532003C3EE8 /* Location.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = ""; }; D5B2E89F1C3A780C00C0327D /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D5B2E8A91C3A780C00C0327D /* Compass-iOS-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Compass-iOS-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; D5C629401C3A7FAA007F7B7C /* Compass.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Compass.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -151,10 +151,10 @@ isa = PBXGroup; children = ( D5361FEF1D6C7133003C3EE8 /* Router.swift */, - D5361FF01D6C7133003C3EE8 /* Compass+Navigate.swift */, D5361FF11D6C7133003C3EE8 /* TypeAlias.swift */, D5361FF21D6C7133003C3EE8 /* String+Extensions.swift */, D5361FF31D6C7133003C3EE8 /* Compass.swift */, + D536202B1D6C8532003C3EE8 /* Location.swift */, ); path = Sources; sourceTree = ""; @@ -335,7 +335,7 @@ D5361FFA1D6C7133003C3EE8 /* String+Extensions.swift in Sources */, D5361FF81D6C7133003C3EE8 /* TypeAlias.swift in Sources */, D5361FF41D6C7133003C3EE8 /* Router.swift in Sources */, - D5361FF61D6C7133003C3EE8 /* Compass+Navigate.swift in Sources */, + D536202C1D6C8532003C3EE8 /* Location.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -357,7 +357,7 @@ D5361FFB1D6C7133003C3EE8 /* String+Extensions.swift in Sources */, D5361FF91D6C7133003C3EE8 /* TypeAlias.swift in Sources */, D5361FF51D6C7133003C3EE8 /* Router.swift in Sources */, - D5361FF71D6C7133003C3EE8 /* Compass+Navigate.swift in Sources */, + D536202D1D6C8532003C3EE8 /* Location.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sources/Compass+Navigate.swift b/Sources/Compass+Navigate.swift deleted file mode 100644 index 89afba4..0000000 --- a/Sources/Compass+Navigate.swift +++ /dev/null @@ -1,9 +0,0 @@ -import Foundation - -extension Compass { - - public static func navigate(urn: String, scheme: String = Compass.scheme) { - guard let url = NSURL(string: "\(scheme)\(urn)") else { return } - openURL(url) - } -} diff --git a/Sources/Compass.swift b/Sources/Compass.swift index 52f94f9..256973d 100644 --- a/Sources/Compass.swift +++ b/Sources/Compass.swift @@ -1,23 +1,14 @@ import Foundation -public struct Location { - - public let path: String - public let arguments: [String: String] - public let fragments: [String: AnyObject] - - public var scheme: String { - return Compass.scheme - } -} - public struct Compass { - typealias Result = (route: String, arguments: [String: String], - concreteMatchCount: Int, wildcardMatchCount: Int) + typealias Result = ( + route: String, + arguments: [String: String], + concreteMatchCount: Int, + wildcardMatchCount: Int) private static var internalScheme = "" - public static var delimiter: String = ":" public static var scheme: String { @@ -28,7 +19,6 @@ public struct Compass { public static var routes = [String]() public static func parse(url: NSURL, fragments: [String : AnyObject] = [:]) -> Location? { - let path = url.absoluteString.substringFromIndex(scheme.endIndex) guard !(path.containsString("?") || path.containsString("#")) else { @@ -37,12 +27,12 @@ public struct Compass { let results: [Result] = routes.flatMap { return findMatch($0, pathString: path) - }.sort { (r1: Result, r2: Result) in - if r1.concreteMatchCount == r2.concreteMatchCount { - return r1.wildcardMatchCount > r2.wildcardMatchCount - } + }.sort { (r1: Result, r2: Result) in + if r1.concreteMatchCount == r2.concreteMatchCount { + return r1.wildcardMatchCount > r2.wildcardMatchCount + } - return r1.concreteMatchCount > r2.concreteMatchCount + return r1.concreteMatchCount > r2.concreteMatchCount } if let result = results.first { @@ -56,7 +46,6 @@ public struct Compass { guard let route = url.host else { return nil } let urlComponents = NSURLComponents(URL: url, resolvingAgainstBaseURL: false) - var arguments = [String : String]() urlComponents?.queryItems?.forEach { queryItem in @@ -70,9 +59,7 @@ public struct Compass { return Location(path: route, arguments: arguments, fragments: fragments) } - static func findMatch(routeString: String, pathString: String) - -> Result? { - + static func findMatch(routeString: String, pathString: String) -> Result? { let routes = routeString.split(delimiter) let paths = pathString.split(delimiter) @@ -98,29 +85,17 @@ public struct Compass { } } - return (route: routeString, arguments: arguments, - concreteMatchCount: concreteMatchCount, wildcardMatchCount: wildcardMatchCount) + return (route: routeString, + arguments: arguments, + concreteMatchCount: concreteMatchCount, + wildcardMatchCount: wildcardMatchCount) } } -private extension String { - - func queryParameters() -> [String: String] { - var parameters = [String: String]() - - let separatorCharacters = NSCharacterSet(charactersInString: "&;") - self.componentsSeparatedByCharactersInSet(separatorCharacters).forEach { (pair) in - - if let equalSeparator = pair.rangeOfString("=") { - let name = pair.substringToIndex(equalSeparator.startIndex) - let value = pair.substringFromIndex(equalSeparator.startIndex.advancedBy(1)) - let cleaned = value.stringByRemovingPercentEncoding ?? value - - parameters[name] = cleaned - } - } - - return parameters - } +extension Compass { + public static func navigate(urn: String, scheme: String = Compass.scheme) { + guard let url = NSURL(string: "\(scheme)\(urn)") else { return } + openURL(url) + } } diff --git a/Sources/Location.swift b/Sources/Location.swift new file mode 100644 index 0000000..3e67304 --- /dev/null +++ b/Sources/Location.swift @@ -0,0 +1,16 @@ +public struct Location { + + public let path: String + public let arguments: [String: String] + public let fragments: [String: AnyObject] + + public var scheme: String { + return Compass.scheme + } + + public init(path: String, arguments: [String: String] = [:], fragments: [String: AnyObject]) { + self.path = path + self.arguments = arguments + self.fragments = fragments + } +} diff --git a/Sources/String+Extensions.swift b/Sources/String+Extensions.swift index ad6160f..eacc3e9 100644 --- a/Sources/String+Extensions.swift +++ b/Sources/String+Extensions.swift @@ -1,3 +1,5 @@ +import Foundation + extension String { func split(delimiter: String) -> [String] { @@ -8,4 +10,22 @@ extension String { func replace(string: String, with withString: String) -> String { return stringByReplacingOccurrencesOfString(string, withString: withString) } + + func queryParameters() -> [String: String] { + var parameters = [String: String]() + + let separatorCharacters = NSCharacterSet(charactersInString: "&;") + self.componentsSeparatedByCharactersInSet(separatorCharacters).forEach { (pair) in + + if let equalSeparator = pair.rangeOfString("=") { + let name = pair.substringToIndex(equalSeparator.startIndex) + let value = pair.substringFromIndex(equalSeparator.startIndex.advancedBy(1)) + let cleaned = value.stringByRemovingPercentEncoding ?? value + + parameters[name] = cleaned + } + } + + return parameters + } } From c631de213e1b4c1a4c0ec604a08191fe656ff3e4 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 15:27:29 +0200 Subject: [PATCH 14/19] Update tests --- Sources/Location.swift | 2 +- Tests/Compass/CompassTests.swift | 164 +++++++++++++++---------------- Tests/Compass/Helpers.swift | 2 +- Tests/Compass/RouterTests.swift | 4 +- 4 files changed, 86 insertions(+), 86 deletions(-) diff --git a/Sources/Location.swift b/Sources/Location.swift index 3e67304..5f26382 100644 --- a/Sources/Location.swift +++ b/Sources/Location.swift @@ -8,7 +8,7 @@ public struct Location { return Compass.scheme } - public init(path: String, arguments: [String: String] = [:], fragments: [String: AnyObject]) { + public init(path: String, arguments: [String: String] = [:], fragments: [String: AnyObject] = [:]) { self.path = path self.arguments = arguments self.fragments = fragments diff --git a/Tests/Compass/CompassTests.swift b/Tests/Compass/CompassTests.swift index 33e8d77..d1deab3 100644 --- a/Tests/Compass/CompassTests.swift +++ b/Tests/Compass/CompassTests.swift @@ -29,235 +29,235 @@ class CompassTests: XCTestCase { func testParseArguments() { let url = NSURL(string: "compassTests://profile:testUser")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual("profile:{user}", route.route) - XCTAssertEqual(route.arguments["user"], "testUser") + XCTAssertEqual("profile:{user}", location.path) + XCTAssertEqual(location.arguments["user"], "testUser") } func testParseFragments() { let url = NSURL(string: "compassTests://profile:testUser")! - guard let route = Compass.parse(url, fragments: ["meta" : "foo"]) else { + guard let location = Compass.parse(url, fragments: ["meta" : "foo"]) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual("profile:{user}", route.route) - XCTAssertEqual(route.arguments["user"], "testUser") - XCTAssertEqual("foo" , route.fragments["meta"] as? String) + XCTAssertEqual("profile:{user}", location.path) + XCTAssertEqual(location.arguments["user"], "testUser") + XCTAssertEqual("foo" , location.fragments["meta"] as? String) } func testParseRouteConcreateMatchCount() { let url = NSURL(string: "compassTests://profile:admin")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual("profile:admin", route.route) - XCTAssert(route.arguments.isEmpty) + XCTAssertEqual("profile:admin", location.path) + XCTAssert(location.arguments.isEmpty) } func testParseRouteWildcardMatchCount() { let url = NSURL(string: "compassTests://profile:jack")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual("profile:{user}", route.route) - XCTAssertEqual(route.arguments["user"], "jack") + XCTAssertEqual("profile:{user}", location.path) + XCTAssertEqual(location.arguments["user"], "jack") } func testParseRouteSamePrefix() { let url = NSURL(string: "compassTests://user:list")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual("user:list", route.route) - XCTAssert(route.arguments.isEmpty) + XCTAssertEqual("user:list", location.path) + XCTAssert(location.arguments.isEmpty) } func testParseMultipleArguments() { let url = NSURL(string: "compassTests://user:list:1:admin")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual("user:list:{userId}:{kind}", route.route) - XCTAssertEqual(route.arguments["userId"], "1") - XCTAssertEqual(route.arguments["kind"], "admin") + XCTAssertEqual("user:list:{userId}:{kind}", location.path) + XCTAssertEqual(location.arguments["userId"], "1") + XCTAssertEqual(location.arguments["kind"], "admin") } func testParseMultipleArgumentsWithFirstWildcard() { let url = NSURL(string: "compassTests://12:user:list:1:admin")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual("{appId}:user:list:{userId}:{kind}", route.route) - XCTAssertEqual(route.arguments["appId"], "12") - XCTAssertEqual(route.arguments["userId"], "1") - XCTAssertEqual(route.arguments["kind"], "admin") + XCTAssertEqual("{appId}:user:list:{userId}:{kind}", location.path) + XCTAssertEqual(location.arguments["appId"], "12") + XCTAssertEqual(location.arguments["userId"], "1") + XCTAssertEqual(location.arguments["kind"], "admin") } func testParseWithoutArguments() { let url = NSURL(string: "compassTests://login")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual("login", route.route) - XCTAssert(route.arguments.isEmpty) + XCTAssertEqual("login", location.path) + XCTAssert(location.arguments.isEmpty) } func testParseRegularURLWithFragments() { let url = NSURL(string: "compassTests://callback/#access_token=IjvcgrkQk1p7TyJxKa26rzM1wBMFZW6XoHK4t5Gkt1xQLTN8l7ppR0H3EZXpoP0uLAN49oCDqTHsvnEV&token_type=Bearer&expires_in=3600")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual(route.route, "callback") - XCTAssertEqual(route.arguments.count, 3) - XCTAssertEqual(route.arguments["access_token"], "IjvcgrkQk1p7TyJxKa26rzM1wBMFZW6XoHK4t5Gkt1xQLTN8l7ppR0H3EZXpoP0uLAN49oCDqTHsvnEV") - XCTAssertEqual(route.arguments["expires_in"], "3600") - XCTAssertEqual(route.arguments["token_type"], "Bearer") + XCTAssertEqual(location.path, "callback") + XCTAssertEqual(location.arguments.count, 3) + XCTAssertEqual(location.arguments["access_token"], "IjvcgrkQk1p7TyJxKa26rzM1wBMFZW6XoHK4t5Gkt1xQLTN8l7ppR0H3EZXpoP0uLAN49oCDqTHsvnEV") + XCTAssertEqual(location.arguments["expires_in"], "3600") + XCTAssertEqual(location.arguments["token_type"], "Bearer") } func testParseRegularURLWithFragmentsAndGoogleOAuth2AccessToken() { let url = NSURL(string: "compassTests://callback/#access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual(route.route, "callback") - XCTAssertEqual(route.arguments.count, 3) - XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") - XCTAssertEqual(route.arguments["expires_in"], "3600") - XCTAssertEqual(route.arguments["token_type"], "Bearer") + XCTAssertEqual(location.path, "callback") + XCTAssertEqual(location.arguments.count, 3) + XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") + XCTAssertEqual(location.arguments["expires_in"], "3600") + XCTAssertEqual(location.arguments["token_type"], "Bearer") } func testParseRegularURLWithFragmentsAndAlternativeAccessToken() { let url = NSURL(string: "compassTests://callback/#access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual(route.route, "callback") - XCTAssertEqual(route.arguments.count, 3) - XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") - XCTAssertEqual(route.arguments["expires_in"], "3600") - XCTAssertEqual(route.arguments["token_type"], "Bearer") + XCTAssertEqual(location.path, "callback") + XCTAssertEqual(location.arguments.count, 3) + XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") + XCTAssertEqual(location.arguments["expires_in"], "3600") + XCTAssertEqual(location.arguments["token_type"], "Bearer") } func testParseRegularURLWithSlashQuery() { let url = NSURL(string: "compassTests://callback/?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual(route.route, "callback") - XCTAssertEqual(route.arguments.count, 3) - XCTAssertEqual(route.arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l") - XCTAssertEqual(route.arguments["expires_in"], "3600") - XCTAssertEqual(route.arguments["token_type"], "Bearer") + XCTAssertEqual(location.path, "callback") + XCTAssertEqual(location.arguments.count, 3) + XCTAssertEqual(location.arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l") + XCTAssertEqual(location.arguments["expires_in"], "3600") + XCTAssertEqual(location.arguments["token_type"], "Bearer") } func testParseRegularURLWithSlashQueryAndGoogleOAuth2AccessToken() { let url = NSURL(string: "compassTests://callback/?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual(route.route, "callback") - XCTAssertEqual(route.arguments.count, 3) - XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") - XCTAssertEqual(route.arguments["expires_in"], "3600") - XCTAssertEqual(route.arguments["token_type"], "Bearer") + XCTAssertEqual(location.path, "callback") + XCTAssertEqual(location.arguments.count, 3) + XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") + XCTAssertEqual(location.arguments["expires_in"], "3600") + XCTAssertEqual(location.arguments["token_type"], "Bearer") } func testParseRegularURLWithSlashQueryAndAlternativeAccessToken() { let url = NSURL(string: "compassTests://callback/?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual(route.route, "callback") - XCTAssertEqual(route.arguments.count, 3) - XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") - XCTAssertEqual(route.arguments["expires_in"], "3600") - XCTAssertEqual(route.arguments["token_type"], "Bearer") + XCTAssertEqual(location.path, "callback") + XCTAssertEqual(location.arguments.count, 3) + XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") + XCTAssertEqual(location.arguments["expires_in"], "3600") + XCTAssertEqual(location.arguments["token_type"], "Bearer") } func testParseRegularURLWithQuery() { let url = NSURL(string: "compassTests://callback?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual(route.route, "callback") - XCTAssertEqual(route.arguments.count, 3) - XCTAssertEqual(route.arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l") - XCTAssertEqual(route.arguments["expires_in"], "3600") - XCTAssertEqual(route.arguments["token_type"], "Bearer") + XCTAssertEqual(location.path, "callback") + XCTAssertEqual(location.arguments.count, 3) + XCTAssertEqual(location.arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l") + XCTAssertEqual(location.arguments["expires_in"], "3600") + XCTAssertEqual(location.arguments["token_type"], "Bearer") } func testParseRegularURLWithQueryAndGoogleOAuth2AccessToken() { let url = NSURL(string: "compassTests://callback?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual(route.route, "callback") - XCTAssertEqual(route.arguments.count, 3) - XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") - XCTAssertEqual(route.arguments["expires_in"], "3600") - XCTAssertEqual(route.arguments["token_type"], "Bearer") + XCTAssertEqual(location.path, "callback") + XCTAssertEqual(location.arguments.count, 3) + XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ") + XCTAssertEqual(location.arguments["expires_in"], "3600") + XCTAssertEqual(location.arguments["token_type"], "Bearer") } func testParseRegularURLWithQueryAndAlternativeAccessToken() { let url = NSURL(string: "compassTests://callback?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")! - guard let route = Compass.parse(url) else { + guard let location = Compass.parse(url) else { XCTFail("Compass parsing failed") return } - XCTAssertEqual(route.route, "callback") - XCTAssertEqual(route.arguments.count, 3) - XCTAssertEqual(route.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") - XCTAssertEqual(route.arguments["expires_in"], "3600") - XCTAssertEqual(route.arguments["token_type"], "Bearer") + XCTAssertEqual(location.path, "callback") + XCTAssertEqual(location.arguments.count, 3) + XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=") + XCTAssertEqual(location.arguments["expires_in"], "3600") + XCTAssertEqual(location.arguments["token_type"], "Bearer") } } diff --git a/Tests/Compass/Helpers.swift b/Tests/Compass/Helpers.swift index 80e24b3..2709968 100644 --- a/Tests/Compass/Helpers.swift +++ b/Tests/Compass/Helpers.swift @@ -7,7 +7,7 @@ class TestRoute: Routable { var resolved = false - func resolve(arguments: [String: String], fragments: [String : AnyObject] = [:], currentController controller: Controller) { + func navigate(to location: Location, from currentController: Controller) { resolved = true } } diff --git a/Tests/Compass/RouterTests.swift b/Tests/Compass/RouterTests.swift index 30b421e..a14dd15 100644 --- a/Tests/Compass/RouterTests.swift +++ b/Tests/Compass/RouterTests.swift @@ -15,13 +15,13 @@ class RouterTests: XCTestCase { func testNavigateIfRouteRegistered() { router.routes["test"] = route - router.navigate("test", arguments: [:], from: controller) + router.navigate(to: Location(path: "test"), from: controller) XCTAssertTrue(route.resolved) } func testNavigateIfRouteNotRegistered() { - router.navigate("test", arguments: [:], from: controller) + router.navigate(to: Location(path: "test"), from: controller) XCTAssertFalse(route.resolved) } From 1f4a8f910bce104e742a5b0b4a2b6033d06ac42b Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 15:42:45 +0200 Subject: [PATCH 15/19] Update readme --- README.md | 88 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index c31e00f..631804a 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ First you need to register a URL scheme for your application #### Step 2 Now you need to configure Compass to use that URL scheme, a good place to do this is in your `AppDelegate` + ```swift func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { @@ -33,6 +34,7 @@ func application(application: UIApplication, ``` #### Step 3 Configure your application routes + ```swift func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { @@ -43,25 +45,30 @@ func application(application: UIApplication, ``` #### Step 4 Set up your application to respond to the URLs, this can be done in the `AppDelegate` but its up to you to find a more suitable place for it depending on the size of your implementation. + ```swift func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { - return Compass.parse(url) { route, arguments in - switch route { - case "profile:{username}": - let profileController = profileController(title: arguments["{username}"]) - self.navigationController?.pushViewController(profileController, - animated: true) - case "login:{username}": - let loginController = LoginController(title: arguments["{username}"]) - self.navigationController?.pushViewController(loginController, - animated: true) - case "logout": - logout() - default: break - } + guard let location = Compass.parse(url) else { + return false } + + let arguments = location.arguments + + switch location.path { + case "profile:{username}": + let profileController = profileController(title: arguments["{username}"]) + self.navigationController?.pushViewController(profileController, animated: true) + case "login:{username}": + let loginController = LoginController(title: arguments["{username}"]) + self.navigationController?.pushViewController(loginController, animated: true) + case "logout": + logout() + default: break + } + + return true } ``` @@ -79,8 +86,9 @@ route handling code and avoid huge `switch` cases. in one place: ```swift struct ProfileRoute: Routable { - func resolve(arguments: [String: String], currentController: UIViewController) { - guard let username = arguments["username"] else { return } + + func navigate(to location: Location, from currentController: UIViewController) { + guard let username = location.arguments["username"] else { return } let profileController = profileController(title: username) currentController.navigationController?.pushViewController(profileController, animated: true) @@ -103,10 +111,13 @@ router.routes = [ func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { - return Compass.parse(url) { route, arguments in - router.navigate(route, arguments: arguments, - navigationController: navigationController) + guard let location = Compass.parse(url) else { + return false } + + router.navigate(to: location, from: navigationController) + + return true } ``` @@ -114,28 +125,25 @@ func application(app: UIApplication, You could have multiple handlers depending on if a user is logged in or not. ```swift struct NavigationHandler { - static func routePreLogin(route: String, arguments: [String: String], - navigationController: UINavigationController) { - switch route { - case "forgotpassword:{username}": - let forgotPasswordController = ForgotPasswordController(title: arguments["{username}"]) - navigationController?.pushViewController(loginController, - animated: true) - default: break - } + + static func routePreLogin(location: Location, navigationController: UINavigationController) { + switch location.path { + case "forgotpassword:{username}": + let controller = ForgotPasswordController(title: location.arguments["{username}"]) + navigationController?.pushViewController(controller, animated: true) + default: break + } } - static func routePostLogin(route: String, arguments: [String: String], - navigationController: UINavigationController) { - switch route { - case "profile:{username}": - let profileController = ProfileController(title: arguments["{username}"]) - navigationController?.pushViewController(profileController, - animated: true) - case "logout": - AppDelegate.logout() - default: break - } + static func routePostLogin(location: Location, navigationController: UINavigationController) { + switch location.path { + case "profile:{username}": + let controller = ProfileController(title: location.arguments["{username}"]) + navigationController?.pushViewController(controller, animated: true) + case "logout": + AppDelegate.logout() + default: break + } } } ``` @@ -154,7 +162,7 @@ routerPostLogin.routes = [ ] let router = isLoggedIn ? routerPostLogin : routerPreLogin -router.navigate(route, arguments: arguments, navigationController: navigationController) +router.navigate(to: location, from: navigationController) ``` ##### Tip 3. Global function From e752d19db469b7035937aa4b6f46d33cd3f783f3 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 15:44:28 +0200 Subject: [PATCH 16/19] Reconfigure travis --- .mention-bot | 4 ++++ .swiftlint.yml | 31 +++++++++++++++++++++++++++++++ .travis.yml | 20 ++++++++++---------- swiftlint.sh | 23 +++++++++++++++++++++++ 4 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 .mention-bot create mode 100644 .swiftlint.yml create mode 100755 swiftlint.sh diff --git a/.mention-bot b/.mention-bot new file mode 100644 index 0000000..2c6b66a --- /dev/null +++ b/.mention-bot @@ -0,0 +1,4 @@ +{ + "maxReviewers": 2, + "requiredOrgs": ["hyperoslo"] +} diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..27e085a --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,31 @@ +included: + - Sources + - Tests +excluded: + - Carthage + - Pods + - Packages +opt_in_rules: + - empty_count +disabled_rules: + - valid_docs +force_cast: warning +force_try: + severity: warning +line_length: 120 +function_body_length: + - 150 +type_body_length: + warning: 300 + error: 400 +file_length: + warning: 500 + error: 1200 +type_name: + min_length: 3 + max_length: + warning: 40 + error: 50 +variable_name: + min_length: 2 +reporter: "xcode" diff --git a/.travis.yml b/.travis.yml index ed6242b..38a8813 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,13 @@ +os: + - osx osx_image: xcode7.3 language: objective-c - -before_install: -- brew update -- if brew outdated | grep -qx xctool; then brew upgrade xctool; fi -- carthage update --platform iOS,Mac - +install: + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./swiftlint.sh; fi script: -- xctool clean build -project Compass.xcodeproj -scheme Compass-iOS -sdk iphonesimulator -- xctool test -project Compass.xcodeproj -scheme Compass-iOS -sdk iphonesimulator -- xctool clean build -project Compass.xcodeproj -scheme Compass-Mac -sdk macosx -- xctool test -project Compass.xcodeproj -scheme Compass-Mac -sdk macosx + - xcodebuild clean build -project Compass.xcodeproj -scheme Compass-iOS -sdk iphonesimulator + - xcodebuild test -project Compass.xcodeproj -scheme Compass-iOS -sdk iphonesimulator + - xcodebuild clean build -project Compass.xcodeproj -scheme Compass-Mac -sdk macosx + - xcodebuild test -project Compass.xcodeproj -scheme Compass-Mac -sdk macosx +notifications: + email: false diff --git a/swiftlint.sh b/swiftlint.sh new file mode 100755 index 0000000..04d63ef --- /dev/null +++ b/swiftlint.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Installs the SwiftLint package. + +set -e + +SWIFTLINT_SOURCE_URL="https://github.com/realm/SwiftLint.git" +SWIFTLINT_SOURCE_PATH="/tmp/SwiftLint" +SWIFTLINT_PKG_PATH="/tmp/SwiftLint.pkg" +SWIFTLINT_PKG_URL="https://github.com/realm/SwiftLint/releases/download/0.11.1/SwiftLint.pkg" + +wget --output-document=$SWIFTLINT_PKG_PATH $SWIFTLINT_PKG_URL + +if [ -f $SWIFTLINT_PKG_PATH ]; then + echo "Installing SwiftLint..." + sudo installer -pkg $SWIFTLINT_PKG_PATH -target / +else + echo "Failed to install SwiftLint. Compiling from source..." && + git clone $SWIFTLINT_SOURCE_URL $SWIFTLINT_SOURCE_PATH && + cd $SWIFTLINT_SOURCE_PATH && + git submodule update --init --recursive && + sudo make install +fi From f78f607f424a3584fd7e51c2c369c352ff8346fb Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 15:45:14 +0200 Subject: [PATCH 17/19] Fix linting --- .swiftlint.yml | 1 - Sources/Router.swift | 1 - 2 files changed, 2 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 27e085a..8034f5f 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,6 +1,5 @@ included: - Sources - - Tests excluded: - Carthage - Pods diff --git a/Sources/Router.swift b/Sources/Router.swift index 716fa3c..ac05da5 100644 --- a/Sources/Router.swift +++ b/Sources/Router.swift @@ -14,4 +14,3 @@ public struct Router: Routable { route.navigate(to: location, from: currentController) } } - From 6d692659863ac539a5f9e2d5c5cc4c5a9c5c877e Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 16:06:09 +0200 Subject: [PATCH 18/19] Update podspec --- Compass.podspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Compass.podspec b/Compass.podspec index 8ee99b6..0cb91e6 100644 --- a/Compass.podspec +++ b/Compass.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Compass" s.summary = "Compass helps you setup a central navigation system for your iOS application." - s.version = "3.0.0" + s.version = "4.0.0" s.homepage = "https://github.com/hyperoslo/Compass" s.license = 'MIT' s.author = { "Hyper Interaktiv AS" => "ios@hyper.no" } @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.requires_arc = true - s.ios.source_files = 'Sources/{iOS,Shared}/**/*' - s.osx.source_files = 'Sources/{Mac,Shared}/**/*' - s.dependency 'Sugar' + s.ios.source_files = 'Sources/**/*' + s.osx.source_files = 'Sources/**/*' + s.frameworks = 'Foundation' end From 76d6af03cea5fc7954de1a475b916f76a0259946 Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Tue, 23 Aug 2016 20:54:40 +0200 Subject: [PATCH 19/19] 3.0.0 --- Compass.podspec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Compass.podspec b/Compass.podspec index 0cb91e6..2334e6b 100644 --- a/Compass.podspec +++ b/Compass.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Compass" s.summary = "Compass helps you setup a central navigation system for your iOS application." - s.version = "4.0.0" + s.version = "3.0.0" s.homepage = "https://github.com/hyperoslo/Compass" s.license = 'MIT' s.author = { "Hyper Interaktiv AS" => "ios@hyper.no" } @@ -13,7 +13,6 @@ Pod::Spec.new do |s| s.requires_arc = true - s.ios.source_files = 'Sources/**/*' - s.osx.source_files = 'Sources/**/*' + s.source_files = 'Sources/**/*' s.frameworks = 'Foundation' end