Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created February 6, 2020 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/1b943b64ea999c57d4452c9f399901dc to your computer and use it in GitHub Desktop.
Save BetterProgramming/1b943b64ea999c57d4452c9f399901dc to your computer and use it in GitHub Desktop.
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