1.4.0 - Get Results by Closure
Add
Now you can return the result of the route execution through the closure
.
Try the following code (Take get
as an example, The same method works for do
and viewController
):
- Register route
Router<Examples>.register(for: "Examples") { (url, value, callback: @escaping GetResultCallback) in
DispatchQueue.main.async {
callback(.success("Examples String"))
}
}
- Execute route:
Router<Examples>.get(of: String.self, from: "Examples") { (result) in
switch result {
case .success(let string):
print(string)
case .failure(let error):
print(error)
}
}