Search code examples
iosswiftxcode8swiftr

SwiftR Invoke method callBack Handler


I am using swiftR in my IOS application, how can handle this error in invoke method and get response from server?

Call can throw, but it is not marked with 'try' and the error is not handled

hub.invoke("Auth_Code_Request", arguments: [mobile,myMethod!], callback: { (result, error) -> () in

                do {

                    try
                        print(result ?? "this is result")
                }

                catch {

                    print(error)
                }
            })

Solution

  • That's mean invoke method can throw an exception. Surround it with a do-catch and use the try keyword.

    Example:

    do{
     try myMethod()
    } catch {
    
    }