Skip to content

1.4.0 - Get Results by Closure

Compare
Choose a tag to compare
@rakuyoMo rakuyoMo released this 07 Jul 02:59
· 41 commits to master since this release

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)
    }
}