-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
587 additions
and
667 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Foundation | ||
|
||
extension Decodable { | ||
static internal func from<T: Decodable>(json: String, using encoding: String.Encoding = .utf8) -> T? { | ||
guard let data = json.data(using: encoding) else { return nil } | ||
return from(data: data) as T? | ||
} | ||
|
||
static internal func from<T: Decodable>(data: Data) -> T? { | ||
let decoder = JSONDecoder() | ||
return try! decoder.decode(T.self, from: data) as T? | ||
} | ||
} | ||
|
||
struct GenericDecodable<T: Decodable, U: Decodable>: Decodable { | ||
var t: T? | ||
var u: U? | ||
|
||
var value: Decodable? { | ||
return t ?? u | ||
} | ||
|
||
init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
t = try? container.decode(T.self) | ||
u = try? container.decode(U.self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Foundation | ||
|
||
struct DirectionsResponse: Codable { | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case code | ||
case message | ||
case uuid | ||
case routes | ||
case waypoints | ||
} | ||
|
||
let code: String? | ||
let message: String? | ||
let uuid: String? | ||
let routes: [Route]? | ||
let waypoints: [Waypoint]? | ||
} |
Oops, something went wrong.