1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// ContextAccepting.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 |
import UIKit
|
|
15 |
|
|
16 |
/// The protocol for a `UIViewController` to make it compatible with `ContextSettingTask`.
|
|
17 |
public protocol ContextAccepting where Self: UIViewController {
|
|
18 |
|
|
19 |
// MARK: Associated types
|
|
20 |
|
|
21 |
/// Type of `Context` object that `UIViewController` can deal with
|
|
22 |
associatedtype Context
|
|
23 |
|
|
24 |
// MARK: Methods to implement
|
|
25 |
|
|
26 |
/// If `UIViewController` does not support all the permutations that context instance may have -
|
|
27 |
/// setup the check here.
|
|
28 |
///
|
|
29 |
/// - Parameter context: `Context` instance.
|
|
30 |
/// - Throws: throws `Error` if `Context` instance is not supported.
|
|
31 |
static func checkCompatibility(with context: Context) throws
|
|
32 |
|
|
33 |
/// `ContextSettingTask` will call this method to provide the `Context` instance to the `UIViewController`
|
|
34 |
/// that has just been build or found.
|
|
35 |
///
|
|
36 |
/// - Parameter context: `Context` instance.
|
|
37 |
/// - Throws: throws `Error` if `Context` instance is not supported. `Router` will stop building the rest of the stack in this case.
|
|
38 |
func setup(with context: Context) throws
|
|
39 |
|
|
40 |
}
|
|
41 |
|
|
42 |
// MARK: Default implementation
|
|
43 |
|
|
44 |
public extension ContextAccepting {
|
|
45 |
|
|
46 |
/// Default implementation does nothing.
|
|
47 |
static func checkCompatibility(with context: Context) throws {}
|
1x |
48 |
|
|
49 |
}
|
|