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.
agent.start() is a suspending void function. We can call it like so:
// Await
let error: ProvenError? = await agent.
[agent startStartUpTimeout: nil
completion:
didExchange.getAll() is a suspend function that returns an Array of DidExchangeRecord. We can call it like so:
We also have support for (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:
// Await
let (records, error) = await agent.didExchange.getAll()
if (error != nil) {
print("Error getting connections")
} else {
print("Connections: \(records!.count)")
}
// Or use a completion handler
agent.didExchange.getAll { records, error in
if (error != nil) {
print("Error getting connections")
} else {
print("Connections: \(records!.count)")
}
}[agent.didExchange
getAllCompletion:^(
NSArray<ProvenmobileDidExchangeRecord *> *_Nullable records,
ProvenmobileProvenError *_Nullable error
){
if(error){
// Handle error
}else{
NSLog(@"Connections: %lu", records.count);
}
}
];import KMPNativeCoroutinesAsync
// Agent.start() example
_ = try await asyncFunction(for: agent.start(startUpTimeout: nil))
// DidExchange.getAll() example
let records = try await asyncFunction(for: agent.didExchange.getAll())
print("Connections: \(records.count)")