Created
February 6, 2020 20:16
-
-
Save BetterProgramming/1b943b64ea999c57d4452c9f399901dc to your computer and use it in GitHub Desktop.
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
extension AnyRoute: Decodable { | |
static var contextUserInfoKey: CodingUserInfoKey { | |
// swiftlint:disable:next force_unwrapping | |
return CodingUserInfoKey(rawValue: "routerservice_anyroute_context")! | |
} | |
public init(from decoder: Decoder) throws { | |
let ctx = decoder.userInfo[AnyRoute.contextUserInfoKey] | |
guard let context = ctx as? RouterServiceAnyRouteDecodingProtocol else { | |
preconditionFailure("TRIED TO DECODE ANYROUTE WITHOUT A CONTEXT!") | |
} | |
let data = try context.decodeAnyRoute(fromDecoder: decoder) | |
self.value = data.0 | |
self.routeString = data.1 | |
} | |
} | |
public protocol RouterServiceAnyRouteDecodingProtocol { | |
func decodeAnyRoute(fromDecoder decoder: Decoder) throws -> (Route, String) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment