Skip to content

Commit d5833d6

Browse files
authored
Merge pull request #40 from hyperoslo/swift-3
Update to Swift 3
2 parents 84242c0 + 89f4e49 commit d5833d6

12 files changed

Lines changed: 110 additions & 108 deletions

File tree

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
os:
2-
- osx
3-
osx_image: xcode7.3
1+
osx_image: xcode8
42
language: objective-c
3+
54
install:
65
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./swiftlint.sh; fi
76
script:
87
- xcodebuild clean build -project Compass.xcodeproj -scheme Compass-iOS -sdk iphonesimulator
9-
- xcodebuild test -project Compass.xcodeproj -scheme Compass-iOS -sdk iphonesimulator
8+
- xcodebuild test -project Compass.xcodeproj -scheme "Compass-iOS" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.0'
109
- xcodebuild clean build -project Compass.xcodeproj -scheme Compass-Mac -sdk macosx
1110
- xcodebuild test -project Compass.xcodeproj -scheme Compass-Mac -sdk macosx
1211
notifications:

Compass.podspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ Pod::Spec.new do |s|
1515

1616
s.source_files = 'Sources/**/*'
1717
s.frameworks = 'Foundation'
18+
19+
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0' }
1820
end

Compass.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,11 @@
263263
TargetAttributes = {
264264
D5B2E89E1C3A780C00C0327D = {
265265
CreatedOnToolsVersion = 7.2;
266+
LastSwiftMigration = 0800;
266267
};
267268
D5B2E8A81C3A780C00C0327D = {
268269
CreatedOnToolsVersion = 7.2;
270+
LastSwiftMigration = 0800;
269271
};
270272
D5C6293F1C3A7FAA007F7B7C = {
271273
CreatedOnToolsVersion = 7.2;
@@ -495,6 +497,7 @@
495497
PRODUCT_NAME = Compass;
496498
SKIP_INSTALL = YES;
497499
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
500+
SWIFT_VERSION = 3.0;
498501
};
499502
name = Debug;
500503
};
@@ -514,6 +517,7 @@
514517
PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.Compass-iOS";
515518
PRODUCT_NAME = Compass;
516519
SKIP_INSTALL = YES;
520+
SWIFT_VERSION = 3.0;
517521
};
518522
name = Release;
519523
};
@@ -527,6 +531,7 @@
527531
PRODUCT_BUNDLE_IDENTIFIER = no.hyper.CompassTests;
528532
PRODUCT_NAME = "$(TARGET_NAME)";
529533
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
534+
SWIFT_VERSION = 3.0;
530535
};
531536
name = Debug;
532537
};
@@ -539,6 +544,7 @@
539544
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
540545
PRODUCT_BUNDLE_IDENTIFIER = no.hyper.CompassTests;
541546
PRODUCT_NAME = "$(TARGET_NAME)";
547+
SWIFT_VERSION = 3.0;
542548
};
543549
name = Release;
544550
};
@@ -563,6 +569,7 @@
563569
SDKROOT = macosx;
564570
SKIP_INSTALL = YES;
565571
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
572+
SWIFT_VERSION = 3.0;
566573
};
567574
name = Debug;
568575
};
@@ -586,6 +593,7 @@
586593
PRODUCT_NAME = Compass;
587594
SDKROOT = macosx;
588595
SKIP_INSTALL = YES;
596+
SWIFT_VERSION = 3.0;
589597
};
590598
name = Release;
591599
};
@@ -601,6 +609,7 @@
601609
PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.Compass-MacTests";
602610
PRODUCT_NAME = "$(TARGET_NAME)";
603611
SDKROOT = macosx;
612+
SWIFT_VERSION = 3.0;
604613
};
605614
name = Debug;
606615
};
@@ -616,6 +625,7 @@
616625
PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.Compass-MacTests";
617626
PRODUCT_NAME = "$(TARGET_NAME)";
618627
SDKROOT = macosx;
628+
SWIFT_VERSION = 3.0;
619629
};
620630
name = Release;
621631
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![License](https://img.shields.io/cocoapods/l/Compass.svg?style=flat)](http://cocoadocs.org/docsets/Compass)
66
[![Platform](https://img.shields.io/cocoapods/p/Compass.svg?style=flat)](http://cocoadocs.org/docsets/Compass)
77
[![CI Status](http://img.shields.io/travis/hyperoslo/Compass.svg?style=flat)](https://travis-ci.org/hyperoslo/Compass)
8+
![Swift](https://img.shields.io/badge/%20in-swift%203.0-orange.svg)
89

910
Compass helps you setup a central navigation system for your application.
1011
This has many benefits, one of them being that controllers can now be

Sources/Compass.swift

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public struct Compass {
88
concreteMatchCount: Int,
99
wildcardMatchCount: Int)
1010

11-
private static var internalScheme = ""
11+
fileprivate static var internalScheme = ""
1212
public static var delimiter: String = ":"
1313

1414
public static var scheme: String {
@@ -18,21 +18,21 @@ public struct Compass {
1818

1919
public static var routes = [String]()
2020

21-
public static func parse(url: NSURL, payload: Any? = nil) -> Location? {
22-
let path = url.absoluteString.substringFromIndex(scheme.endIndex)
21+
public static func parse(url: URL, payload: Any? = nil) -> Location? {
22+
let path = url.absoluteString.substring(from: scheme.endIndex)
2323

24-
guard !(path.containsString("?") || path.containsString("#")) else {
25-
return parseAsURL(url, payload: payload)
24+
guard !(path.contains("?") || path.contains("#")) else {
25+
return parseComponents(url: url, payload: payload)
2626
}
2727

2828
let results: [Result] = routes.flatMap {
29-
return findMatch($0, pathString: path)
30-
}.sort { (r1: Result, r2: Result) in
31-
if r1.concreteMatchCount == r2.concreteMatchCount {
32-
return r1.wildcardMatchCount > r2.wildcardMatchCount
33-
}
29+
return findMatch(routeString: $0, pathString: path)
30+
}.sorted { (r1: Result, r2: Result) in
31+
if r1.concreteMatchCount == r2.concreteMatchCount {
32+
return r1.wildcardMatchCount > r2.wildcardMatchCount
33+
}
3434

35-
return r1.concreteMatchCount > r2.concreteMatchCount
35+
return r1.concreteMatchCount > r2.concreteMatchCount
3636
}
3737

3838
if let result = results.first {
@@ -42,10 +42,10 @@ public struct Compass {
4242
return nil
4343
}
4444

45-
static func parseAsURL(url: NSURL, payload: Any? = nil) -> Location? {
45+
static func parseComponents(url: URL, payload: Any? = nil) -> Location? {
4646
guard let route = url.host else { return nil }
4747

48-
let urlComponents = NSURLComponents(URL: url, resolvingAgainstBaseURL: false)
48+
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
4949
var arguments = [String : String]()
5050

5151
urlComponents?.queryItems?.forEach { queryItem in
@@ -71,7 +71,8 @@ public struct Compass {
7171

7272
for (route, path) in zip(routes, paths) {
7373
if route.hasPrefix("{") {
74-
let key = route.replace("{", with: "").replace("}", with: "")
74+
let key = route.replacingOccurrences(of: "{", with: "")
75+
.replacingOccurrences(of: "}", with: "")
7576
arguments[key] = path
7677

7778
wildcardMatchCount += 1
@@ -94,8 +95,8 @@ public struct Compass {
9495

9596
extension Compass {
9697

97-
public static func navigate(urn: String, scheme: String = Compass.scheme) {
98-
guard let url = NSURL(string: "\(scheme)\(urn)") else { return }
99-
openURL(url)
98+
public static func navigate(to urn: String, scheme: String = Compass.scheme) {
99+
guard let url = URL(string: "\(scheme)\(urn)") else { return }
100+
open(url: url)
100101
}
101102
}

Sources/Router.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
public enum RouteError: ErrorType {
2-
case NotFound
3-
case InvalidArguments(Location)
4-
case InvalidPayload(Location)
1+
public enum RouteError: Error {
2+
case notFound
3+
case invalidArguments(Location)
4+
case invalidPayload(Location)
55
}
66

77
public protocol Routable {
88

9-
func navigate(to location: Location, from currentController: Controller) throws
9+
func navigate(to location: Location, from currentController: CurrentController) throws
1010
}
1111

1212
public protocol ErrorRoutable {
1313

14-
func handle(routeError: ErrorType, from currentController: Controller)
14+
func handle(routeError error: Error, from currentController: CurrentController)
1515
}
1616

1717
public struct Router: Routable {
@@ -21,16 +21,16 @@ public struct Router: Routable {
2121

2222
public init() {}
2323

24-
public func navigate(to location: Location, from currentController: Controller) {
24+
public func navigate(to location: Location, from currentController: CurrentController) {
2525
guard let route = routes[location.path] else {
26-
errorRoute?.handle(RouteError.NotFound, from: currentController)
26+
errorRoute?.handle(routeError: RouteError.notFound, from: currentController)
2727
return
2828
}
2929

3030
do {
3131
try route.navigate(to: location, from: currentController)
3232
} catch {
33-
errorRoute?.handle(error, from: currentController)
33+
errorRoute?.handle(routeError: error, from: currentController)
3434
}
3535
}
3636
}

Sources/String+Extensions.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@ import Foundation
22

33
extension String {
44

5-
func split(delimiter: String) -> [String] {
6-
let components = componentsSeparatedByString(delimiter)
5+
func split(_ delimiter: String) -> [String] {
6+
let components = self.components(separatedBy: delimiter)
77
return components != [""] ? components : []
88
}
99

10-
func replace(string: String, with withString: String) -> String {
11-
return stringByReplacingOccurrencesOfString(string, withString: withString)
12-
}
13-
1410
func queryParameters() -> [String: String] {
1511
var parameters = [String: String]()
1612

17-
let separatorCharacters = NSCharacterSet(charactersInString: "&;")
18-
self.componentsSeparatedByCharactersInSet(separatorCharacters).forEach { (pair) in
13+
let separatorCharacters = CharacterSet(charactersIn: "&;")
14+
self.components(separatedBy: separatorCharacters).forEach { (pair) in
1915

20-
if let equalSeparator = pair.rangeOfString("=") {
21-
let name = pair.substringToIndex(equalSeparator.startIndex)
22-
let value = pair.substringFromIndex(equalSeparator.startIndex.advancedBy(1))
23-
let cleaned = value.stringByRemovingPercentEncoding ?? value
16+
if let equalSeparator = pair.range(of: "=") {
17+
let name = pair.substring(to: equalSeparator.lowerBound)
18+
let value = pair.substring(from: pair.index(equalSeparator.lowerBound, offsetBy: 1))
19+
let cleaned = value.removingPercentEncoding ?? value
2420

2521
parameters[name] = cleaned
2622
}

Sources/TypeAlias.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
#endif
66

77
#if os(OSX)
8-
public typealias Controller = NSViewController
8+
public typealias CurrentController = NSViewController
99

10-
func openURL(URL: NSURL) {
11-
NSWorkspace.sharedWorkspace().openURL(URL)
10+
func open(url: URL) {
11+
NSWorkspace.shared().open(url)
1212
}
1313
#else
14-
public typealias Controller = UIViewController
14+
public typealias CurrentController = UIViewController
1515

16-
func openURL(URL: NSURL) {
17-
UIApplication.sharedApplication().openURL(URL)
16+
func open(url: URL) {
17+
UIApplication.shared.openURL(url)
1818
}
1919
#endif

0 commit comments

Comments
 (0)