Skip to content

Commit 255b23b

Browse files
committedJun 9, 2018
set swiftlint line_length to 100 chars
and reformat code accordingly
1 parent 9c3893a commit 255b23b

File tree

7 files changed

+148
-56
lines changed

7 files changed

+148
-56
lines changed
 

‎.swiftlint.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
disabled_rules:
2-
- line_length
3-
1+
line_length: 100

‎Sources/App.swift

+23-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ public enum App: String {
2121
case moovit
2222

2323
static var all: [App] {
24-
return [.appleMaps, .googleMaps, .citymapper, .transit, .lyft, .uber, .navigon, .waze, .yandex, .moovit]
24+
return [
25+
.appleMaps,
26+
.googleMaps,
27+
.citymapper,
28+
.transit,
29+
.lyft,
30+
.uber,
31+
.navigon,
32+
.waze,
33+
.yandex,
34+
.moovit
35+
]
2536
}
2637

2738
var urlScheme: String {
@@ -54,7 +65,8 @@ public enum App: String {
5465
}
5566
}
5667

57-
/// Validates if an app supports a mode. The given mode is optional and this defaults to `true` if the mode is `nil`.
68+
/// Validates if an app supports a mode. The given mode is optional and this defaults to `true`
69+
/// if the mode is `nil`.
5870
func supports(mode: Mode?) -> Bool {
5971
guard let mode = mode else {
6072
return true
@@ -82,8 +94,11 @@ public enum App: String {
8294

8395
// swiftlint:disable cyclomatic_complexity
8496
// swiftlint:disable function_body_length
85-
/// Build a query string for this app using the parameters. Returns nil if a mode is specified, but not supported by this app.
86-
func queryString(origin: LocationRepresentable?, destination: LocationRepresentable, mode: Mode?) -> String? {
97+
/// Build a query string for this app using the parameters. Returns nil if a mode is specified,
98+
/// but not supported by this app.
99+
func queryString(origin: LocationRepresentable?,
100+
destination: LocationRepresentable,
101+
mode: Mode?) -> String? {
87102
guard self.supports(mode: mode) else {
88103
// if a mode is present, validate if the app supports it, otherwise we don't care
89104
return nil
@@ -133,9 +148,12 @@ public enum App: String {
133148
parameters.set("dropoff[nickname]", destination.name)
134149
return "\(self.urlScheme)?\(parameters.urlParameters)"
135150
case .navigon:
136-
let name = destination.name ?? "Destination" // Docs are unclear about the name being omitted
151+
// Docs are unclear about the name being omitted
152+
let name = destination.name ?? "Destination"
153+
// swiftlint:disable:next line_length
137154
return "\(self.urlScheme)coordinate/\(name.urlQuery ?? "")/\(destination.longitude)/\(destination.latitude)"
138155
case .waze:
156+
// swiftlint:disable:next line_length
139157
return "\(self.urlScheme)?ll=\(destination.latitude),\(destination.longitude)&navigate=yes"
140158
case .yandex:
141159
parameters.set("lat_from", origin?.latitude)

‎Sources/Karte.swift

+45-18
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public enum Karte {
1515
///
1616
/// - Parameter app: a navigation app supported by Karte
1717
/// - Returns: `true` if the app is installed
18-
/// - Warning: For this to return `true` in any case, the necessary url schemes have to be included in your app's Info.plist.
18+
/// - Warning: For this to return `true` in any case, the necessary url schemes have to be
19+
/// included in your app's Info.plist.
1920
/// Please see Karte's README for additional details.
2021
public static func isInstalled(_ app: App) -> Bool {
2122
guard app != .appleMaps else { return true } // FIXME: See issue #3
@@ -27,7 +28,8 @@ public enum Karte {
2728
///
2829
/// - Parameters:
2930
/// - app: the app to be launched
30-
/// - origin: an optional origin location, defaults to the user's locatino if left empty in most apps
31+
/// - origin: an optional origin location, defaults to the user's locatino if left empty in
32+
/// most apps
3133
/// - destination: the location to route to
3234
public static func launch(app: App,
3335
origin: LocationRepresentable? = nil,
@@ -39,10 +41,12 @@ public enum Karte {
3941
///
4042
/// - Parameters:
4143
/// - app: the app to be launched
42-
/// - origin: an optional origin location, defaults to the user's location if left empty in most apps
44+
/// - origin: an optional origin location, defaults to the user's location if left empty in
45+
/// most apps
4346
/// - destination: the location to route to
4447
/// - mode: mode of transport to use
45-
/// - Throws: `Karte.Error.unsupportedMode` if the chosen mode is not supported by the target app
48+
/// - Throws: `Karte.Error.unsupportedMode` if the chosen mode is not supported by the target
49+
/// app
4650
public static func launch(app: App,
4751
origin: LocationRepresentable? = nil,
4852
destination: LocationRepresentable,
@@ -56,13 +60,19 @@ public enum Karte {
5660
mode: Mode?) throws {
5761
guard app != .appleMaps else {
5862
guard app.supports(mode: mode) else { throw Error.unsupportedMode }
59-
// If mode (as in the launchOptions below) stays nil, Apple Maps won't go directly to the route, but show search boxes with prefilled content instead.
60-
let modeKey = (mode?.identifier(for: .appleMaps) as? [String: String]) ?? [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDefault]
61-
MKMapItem.openMaps(with: [origin, destination].compactMap { $0?.mapItem }, launchOptions: modeKey)
63+
let mapItems = [origin, destination].compactMap { $0?.mapItem }
64+
// If mode (as in the launchOptions below) stays nil, Apple Maps won't go directly to
65+
// the route, but show search boxes with prefilled content instead.
66+
let modeKey = (mode?.identifier(for: .appleMaps) as? [String: String])
67+
?? [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDefault]
68+
MKMapItem.openMaps(with: mapItems, launchOptions: modeKey)
6269
return
6370
}
6471

65-
guard let queryString = app.queryString(origin: origin, destination: destination, mode: mode) else {
72+
guard let queryString = app.queryString(origin: origin,
73+
destination: destination,
74+
mode: mode)
75+
else {
6676
throw Error.unsupportedMode
6777
}
6878

@@ -74,13 +84,17 @@ public enum Karte {
7484
UIApplication.shared.open(url, completionHandler: nil)
7585
}
7686

77-
/// Return a `UIAlertController` with all supported apps the device has installed to offer an option for which app to start.
78-
/// Use this instead of `Karte.presentPicker()` if you want to control the presentation of the alert view controller manually.
87+
/// Return a `UIAlertController` with all supported apps the device has installed to offer an
88+
/// option for which app to start.
89+
/// Use this instead of `Karte.presentPicker()` if you want to control the presentation of the
90+
/// alert view controller manually.
7991
///
8092
/// - Parameters:
81-
/// - origin: an optional origin location, defaults to the user's location if left empty in most apps
93+
/// - origin: an optional origin location, defaults to the user's location if left empty in
94+
/// most apps
8295
/// - destination: the location to route to
83-
/// - mode: an optional mode of transport to use, results in only those apps being shown that support this mode
96+
/// - mode: an optional mode of transport to use, results in only those apps being shown that
97+
/// support this mode
8498
/// - title: an optional title for the `UIAlertController`
8599
/// - message: an optional message for the `UIAlertController`
86100
/// - cancel: label for the cancel button, defaults to "Cancel"
@@ -92,15 +106,19 @@ public enum Karte {
92106
title: String? = nil,
93107
message: String? = nil,
94108
cancel: String = "Cancel",
95-
style: UIAlertControllerStyle = .actionSheet) -> UIAlertController {
109+
style: UIAlertControllerStyle = .actionSheet)
110+
-> UIAlertController {
96111
let alert = UIAlertController(title: title, message: message, preferredStyle: style)
97112

98113
App.all
99114
.filter(self.isInstalled)
100115
.filter { $0.supports(mode: mode) } // defaults to true if mode is nil
101116
.map { app in
102117
return UIAlertAction(title: app.name, style: .default, handler: { _ in
103-
try? self._launch(app: app, origin: origin, destination: destination, mode: mode)
118+
try? self._launch(app: app,
119+
origin: origin,
120+
destination: destination,
121+
mode: mode)
104122
})
105123
}
106124
.forEach { alert.addAction($0) }
@@ -110,12 +128,15 @@ public enum Karte {
110128
return alert
111129
}
112130

113-
/// Present a `UIAlertController` with all supported apps the device has installed to offer an option for which app to start.
131+
/// Present a `UIAlertController` with all supported apps the device has installed to offer an
132+
/// option for which app to start.
114133
///
115134
/// - Parameters:
116-
/// - origin: an optional origin location, defaults to the user's location if left empty in most apps
135+
/// - origin: an optional origin location, defaults to the user's location if left empty in
136+
/// most apps
117137
/// - destination: the location to route to
118-
/// - mode: an optional mode of transport to use, results in only those apps being shown that support this mode
138+
/// - mode: an optional mode of transport to use, results in only those apps being shown that
139+
/// support this mode
119140
/// - viewcontroller: a `UIViewController` to present the `UIAlertController` on
120141
/// - title: an optional title for the `UIAlertController`
121142
/// - message: an optional message for the `UIAlertController`
@@ -130,7 +151,13 @@ public enum Karte {
130151
cancel: String = "Cancel",
131152
style: UIAlertControllerStyle = .actionSheet) {
132153

133-
let alert = createPicker(origin: origin, destination: destination, mode: mode, title: title, message: message, cancel: cancel, style: style)
154+
let alert = createPicker(origin: origin,
155+
destination: destination,
156+
mode: mode,
157+
title: title,
158+
message: message,
159+
cancel: cancel,
160+
style: style)
134161

135162
OperationQueue.main.addOperation {
136163
viewcontroller.present(alert, animated: true, completion: nil)

‎Sources/Location.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public struct Location {
2020
self.coordinate = coordinate
2121
}
2222

23-
public init(name: String? = nil, address: String? = nil, latitude: CLLocationDegrees, longitude: CLLocationDegrees) {
23+
public init(name: String? = nil,
24+
address: String? = nil,
25+
latitude: CLLocationDegrees,
26+
longitude: CLLocationDegrees) {
2427
let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
2528
self.init(name: name, address: address, coordinate: coordinate)
2629
}

‎Sources/LocationRepresentable.swift

+14-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public protocol LocationRepresentable {
2020

2121
extension LocationRepresentable {
2222
internal var mapItem: MKMapItem {
23-
let placemark = MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: self.latitude, longitude: self.longitude))
23+
let placemark = MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: self.latitude,
24+
longitude: self.longitude))
2425
let mapItem = MKMapItem(placemark: placemark)
2526
mapItem.name = self.name
2627
return mapItem
@@ -31,6 +32,18 @@ extension LocationRepresentable {
3132
}
3233
}
3334

35+
extension Location: LocationRepresentable {
36+
public var latitude: Double {
37+
return self.coordinate.latitude
38+
}
39+
40+
public var longitude: Double {
41+
return self.coordinate.longitude
42+
}
43+
}
44+
45+
// MARK: CoreLocation helpers
46+
3447
extension CLLocation: LocationRepresentable {
3548
public var latitude: Double {
3649
return self.coordinate.latitude
@@ -58,13 +71,3 @@ extension CLLocationCoordinate2D: LocationRepresentable {
5871
return nil
5972
}
6073
}
61-
62-
extension Location: LocationRepresentable {
63-
public var latitude: Double {
64-
return self.coordinate.latitude
65-
}
66-
67-
public var longitude: Double {
68-
return self.coordinate.longitude
69-
}
70-
}

‎Sources/Mode.swift

+14-6
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ public enum Mode: String {
1919
/// Look up the transport mode identifier name for a given app.
2020
///
2121
/// - Parameter app: navigation app
22-
/// - Returns: For Apple Maps a `[String:String]`, `String` for anything else. `nil` if irrelevant.
22+
/// - Returns: For Apple Maps a `[String:String]`, `String` for anything else. `nil` if
23+
/// irrelevant.
2324
func identifier(for app: App) -> Any? { // swiftlint:disable:this cyclomatic_complexity
2425
switch app {
2526
case .appleMaps:
2627
switch self {
27-
case .walking: return [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking]
28-
case .driving: return [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
29-
case .transit: return [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeTransit]
30-
case .taxi: return [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving] // it is supported, but there's no key for this...
28+
case .walking:
29+
return [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking]
30+
case .driving:
31+
return [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
32+
case .transit:
33+
return [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeTransit]
34+
case .taxi:
35+
// it is supported, but there's no key for this...
36+
return [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
3137
default: return nil
3238
}
3339
case .googleMaps:
@@ -36,7 +42,9 @@ public enum Mode: String {
3642
case .bicycling: return "bicycling"
3743
case .driving: return "driving"
3844
case .transit: return "transit"
39-
case .taxi: return "driving" // just like Apple Maps this actually is supported, but the key isn't specified in the docs... meh.
45+
// just like Apple Maps this actually is supported, but the key isn't specified in the
46+
// docs... meh.
47+
case .taxi: return "driving"
4048
}
4149
case .citymapper, .transit:
4250
return nil

0 commit comments

Comments
 (0)
Please sign in to comment.