https://kotlinlang.org logo
a

Aditya Kurkure

03/07/2022, 3:05 PM
Can I pass a function
(UIBackgroundFetchResult) -> void
from swift to Kotlin? Currently the method I have written in kotlin expects a
(UIKUIBackgroundFetchResult) -> void
when called from swift.
s

Sebastien Leclerc Lavallee

03/08/2022, 3:35 AM
I did a quick test, and yes you can do that. I had a function like:
Copy code
fun doSomething(with: String, completion: (Time) -> Void) { }
And it was callable from Swift code without problem
a

Aditya Kurkure

03/08/2022, 11:51 AM
Thanks. I still have the problem of swift expecting a
UIKUIBackgroundFetchResult
instead of UIBackGroundFetchResult though.
s

Sebastien Leclerc Lavallee

03/08/2022, 2:35 PM
Oh I see… sorry I didn’t understand the question 😅 My bad. So on the Swift side it’s called
UIBackgroundFetchResult
but KMM translate it to
UIKUIBackgroundFetchResult
🤔 Hum… considering they are basically the same but with different names, I would cast the UIKUI version to UI. But this would need to be done on the Swift side.
a

Aditya Kurkure

03/11/2022, 9:01 AM
Just tried this. Unfortunately it doesn't work.
a

Adrian Witaszak

02/14/2023, 2:09 PM
Got the same issue. Did you get that sorted @Aditya Kurkure? I ended up returning result back to swift and handling it there, but that is not a perfect solution.
Copy code
IOSFileKt.awaitResult { result in
            if result.isFailure {
                completionHandler(.failed)
            } else {
                completionHandler(.newData)
            }
        }
a

Aditya Kurkure

02/28/2023, 1:58 PM
Yeah I did something similar. Haven't been able to find any other workaround.
2 Views