| 1 |
//
|
|
| 2 |
// RouteComposer
|
|
| 3 |
// AnyContextBox.swift
|
|
| 4 |
// https://github.com/ekazaev/route-composer
|
|
| 5 |
//
|
|
| 6 |
// Created by Eugene Kazaev in 2018-2022.
|
|
| 7 |
// Distributed under the MIT license.
|
|
| 8 |
//
|
|
| 9 |
// Become a sponsor:
|
|
| 10 |
// https://github.com/sponsors/ekazaev
|
|
| 11 |
//
|
|
| 12 |
|
|
| 13 |
import Foundation
|
|
| 14 |
|
|
| 15 |
struct AnyContextBox<C>: AnyContext {
|
|
| 16 |
let context: C
|
|
| 17 |
|
|
| 18 |
init(_ context: C) {
|
399x |
| 19 |
self.context = context
|
399x |
| 20 |
}
|
399x |
| 21 |
|
|
| 22 |
func value<Context>() throws -> Context {
|
1510x |
| 23 |
guard let typedContext = context as? Context else {
|
1510x |
| 24 |
throw RoutingError.typeMismatch(type: type(of: context),
|
19x |
| 25 |
expectedType: Context.self,
|
19x |
| 26 |
.init("\(String(describing: context.self)) can not be converted to \(String(describing: Context.self))."))
|
19x |
| 27 |
}
|
1490x |
| 28 |
return typedContext
|
1490x |
| 29 |
}
|
1510x |
| 30 |
}
|
|