If I have a Kotlin interface like following for ex...
# touchlab-tools
j
If I have a Kotlin interface like following for example
Copy code
interface SomeKotlinInterface {
    suspend fun someMethod()
}
Is it expected that swift class that implements that interface would look like follwing?
Copy code
class SomeKotlinClass: SomeKotlinInterface{
    func __someMethod(completionHandler: @escaping ((any Error)?) -> Void) {
        <#code#>
    }
    
    func __someMethod() async throws {
        <#code#>
    }    
}
j
that shows just one method being overridden.....not sure why I'm seeing 2
f
Oh, I see. It’s a weird thing caused by how Xcode handles the async Obj-C interop. If you use it to generate the overrides it gives you both “versions” of the same function. You should pick one and delete the other one depending on if you want to implement it as a callback or as the async function. In other words:
func __someMethod(completionHandler: @escaping ((any Error)?) -> Void)
is the real Obj-C function as declared in the header.
func __someMethod() async throws
is an automatically converted signature of the same function. If you implement it, you actually provide implementation for the first function and Swift will take care of converting it back during compilation.
j
ah, ok, perfect...thanks
t
Just to be sure, even though the second one is
async
, it’s actually not participating in cooperative concurrency and won’t support cancellation.
👍 1