diff --git a/Pod/Pod.xcodeproj/project.pbxproj b/Pod/Pod.xcodeproj/project.pbxproj index 3886d2c..5e75782 100644 --- a/Pod/Pod.xcodeproj/project.pbxproj +++ b/Pod/Pod.xcodeproj/project.pbxproj @@ -7,19 +7,17 @@ objects = { /* Begin PBXBuildFile section */ - BD6929341BC528C60063E97E /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD6929331BC528C60063E97E /* TestCompass.swift */; settings = {ASSET_TAGS = (); }; }; - BD93420C1BC4FCF200F25395 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD93420B1BC4FCF200F25395 /* Compass.swift */; settings = {ASSET_TAGS = (); }; }; + BD6929341BC528C60063E97E /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD6929331BC528C60063E97E /* TestCompass.swift */; }; + BD93420C1BC4FCF200F25395 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD93420B1BC4FCF200F25395 /* Compass.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 146D72AC1AB782920058798C /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 146D72B11AB782920058798C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 14A139B21AEFC72B00AD732F /* Tests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Bridging-Header.h"; sourceTree = ""; }; 14C136511AB784B200B7B07A /* .travis.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = .travis.yml; path = ../.travis.yml; sourceTree = ""; }; 14C136521AB784B200B7B07A /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = CONTRIBUTING.md; path = ../CONTRIBUTING.md; sourceTree = ""; }; 14C136541AB784B200B7B07A /* LICENSE.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = LICENSE.md; path = ../LICENSE.md; sourceTree = ""; }; 14C136551AB784B200B7B07A /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; - 14C1365C1AB784BC00B7B07A /* .gitkeep */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; BD6929331BC528C60063E97E /* TestCompass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCompass.swift; sourceTree = ""; }; BD93420B1BC4FCF200F25395 /* Compass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Compass.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -59,7 +57,6 @@ isa = PBXGroup; children = ( 146D72B01AB782920058798C /* Supporting Files */, - 14A139B21AEFC72B00AD732F /* Tests-Bridging-Header.h */, BD6929331BC528C60063E97E /* TestCompass.swift */, ); path = Tests; @@ -87,7 +84,6 @@ 14C1365B1AB784BC00B7B07A /* Source */ = { isa = PBXGroup; children = ( - 14C1365C1AB784BC00B7B07A /* .gitkeep */, BD93420B1BC4FCF200F25395 /* Compass.swift */, ); name = Source; @@ -261,7 +257,8 @@ INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "Tests/Tests-Bridging-Header.h"; + SWIFT_INSTALL_OBJC_HEADER = NO; + SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; @@ -277,7 +274,8 @@ INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "Tests/Tests-Bridging-Header.h"; + SWIFT_INSTALL_OBJC_HEADER = NO; + SWIFT_OBJC_BRIDGING_HEADER = ""; }; name = Release; }; diff --git a/Pod/Tests/TestCompass.swift b/Pod/Tests/TestCompass.swift index 32dee67..5901b91 100644 --- a/Pod/Tests/TestCompass.swift +++ b/Pod/Tests/TestCompass.swift @@ -42,5 +42,4 @@ class TestCompass: XCTestCase { XCTAssert(arguments.isEmpty) } } - } diff --git a/Pod/Tests/Tests-Bridging-Header.h b/Pod/Tests/Tests-Bridging-Header.h deleted file mode 100644 index 1b2cb5d..0000000 --- a/Pod/Tests/Tests-Bridging-Header.h +++ /dev/null @@ -1,4 +0,0 @@ -// -// Use this file to import your target's public headers that you would like to expose to Swift. -// - diff --git a/Source/.gitkeep b/Source/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Source/Compass.swift b/Source/Compass.swift index 7472515..cbfd2e5 100644 --- a/Source/Compass.swift +++ b/Source/Compass.swift @@ -3,6 +3,7 @@ import UIKit public struct Compass { private static var internalScheme = "" + public static var scheme: String { set { Compass.internalScheme = newValue } get { return "\(Compass.internalScheme)://" } @@ -10,7 +11,10 @@ public struct Compass { public static var routes = [String]() - public static func parse(url: NSURL, completion: (route: String, arguments: [String : String]) -> Void) -> Bool { + public typealias ParseCompletion = (route: String, arguments: [String : String]) -> Void + + public static func parse(url: NSURL, completion: ParseCompletion) -> Bool { + var result = false let query = url.absoluteString.substringFromIndex(scheme.endIndex) for route in routes.sort({ $0 < $1 }) { @@ -19,7 +23,7 @@ public struct Compass { .map(String.init)) .first else { continue } - if (query.hasPrefix(prefix) || prefix.hasPrefix(query)) { + if query.hasPrefix(prefix) || prefix.hasPrefix(query) { let queryString = query.stringByReplacingOccurrencesOfString(prefix, withString: "") let queryArguments = paths(queryString) let routeArguments = paths(route).filter { $0.containsString("{") } @@ -32,19 +36,25 @@ public struct Compass { ? queryArguments[index] : nil } completion(route: route, arguments: arguments) - return true + + result = true + break } } } - return false + + return result } public static func navigate(urn: String, scheme: String = Compass.scheme) { let stringURL = "\(scheme)\(urn)" guard let url = NSURL(string: stringURL) else { return } + UIApplication.sharedApplication().openURL(url) } + // MARK: - Private Helpers + private static func paths(urn: String) -> [String] { return urn.characters .split { $0 == ":" }