https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
h

hooliooo

06/21/2019, 9:50 AM
I have networking callbacks with the following signature:
Copy code
fun someAPIRequest(input: String, callback: (SomeModel?, SomeError?) -> Unit) {
   ....
}
From what I read, Kotlin Native interoperability to iOS is Kotlin => Objective-C => Swift, correct? To change that into a Result type I’d implement something like:
Copy code
sealed class  SomeResult<T, E> {
    data class Success<T, E>(val value: T): SomeResult<T, E>()
    data class Failure<T, E>(val value: E): SomeResult<T, E>()
}

fun someAPIRequest(input: String, callback: (SomeResult<SomeModel, SomeError>) -> Unit) {
   ....
}
But then, I’d have to typecast in Swift, correct? I wouldn’t be able to leverage the Swift Result type because it’s a language feature right?
👍 1
k

kpgalligan

06/21/2019, 10:03 AM
You're passing a Swift lambda into the kotlin code, yes? Yeah, you'll need to create a Swift result from your kotlin 'SomeResult'. It would be pretty easy to make some kind of factory in Swift that takes a "standard" Swift callback and creates one that conforms to the Kotlin interop signature
2 Views