iOS Async

We have written custom completion handlers for our asynchronous functions in iOS. All exposed suspending functions include an overload for a completion handler that expects a ProvenError? and the function result (if not a void function). If the ProvenError is not null then there was an error while executing the function and the expected return value will be null.

Void function example

agent.start() is a suspending void function. We can call it like so:

// Await
let error: ProvenError? = await agent.start(startUpTimeout: nil)
if (error != nil) {
    // Handle error
} else {
    print("Agent Started!")
}

// Or use a completion handler
agent.start(startUpTimeout: nil) { error in
    if (error != nil) {
        // Handle error
    } else {
        print("Agent Started!")
    }
}

Returning function example

didExchange.getAll() is a suspend function that returns an Array of DidExchangeRecord. We can call it like so:

KMPNativeCoroutines

We also have support for KMPNativeCoroutines (1.0.0-ALPHA-23) with Swift. To use it you will need to add it to your project and import the desired functions. Here are some examples:

Last updated

Was this helpful?