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

Jan

11/08/2023, 5:02 PM
Hello everyone, I'm Jan Bej-Radzikowski and I'm Android Developer in Payback. Recently we decided to check out the SKIE library, but we stumbled across a bug that stopped us from making further progress. We wanted to expose a repository to iOS that returns a Flow. This is a code that we have in a shared module inside Android project. The issue is that on the iOS side, our Flow doesn't simply convert to the
SkieSwiftFlow<FirstLevel<List<SomeItem>>>
but instead we're getting
SkieSwiftFlow<FirstLevel<NSArray>>
Android code:
Copy code
fun getFlowTwoLevels(): Flow<FirstLevel<List<SomeItem>>>

sealed class FirstLevel<out T> {
    data class Success<T>(
        val secondLevel: SecondLevel<T>
    ): FirstLevel<T>()
}

sealed class SecondLevel<out T> {
    data class Success<T>(
        val result: T,
    ): SecondLevel<T>()

    data class Error(val error: String): SecondLevel<Nothing>()
}
If you'd like to reproduce the bug, please use the repo linked below. It contains Android and iOS demo projects. https://github.com/JasiekRadzik/KMP_SKIE_NSArray/tree/main
a

Alejandro Rios

11/08/2023, 5:45 PM
You can ask in #touchlab-tools
k

kpgalligan

11/08/2023, 6:40 PM
Tried to build but ran into path and config issues on iOS. Will try again later if I get some time.
❤️ 1
j

Jon Bailey

11/08/2023, 10:07 PM
I don't think you can have a list in a generic parameter anywhere and have it come out usable in Swift. (nothing to do with SKIE). Because generics can only work with class types so it has to be NSArray not Swift Array. and Objective-C generics are "lightweight" which for reasons I don't fully understand mean in Swift you just can't do NSArray<SomeItem>.
because Kotlin's List is automatically converted to NSArray in Objective-C it's a bit different than other generic classes. So in my code whenever I need to pass a List in a generic, I use a wrapper like this:
Copy code
public data class ListBox<T>(val value: List<T>)
Then it will be typesafe in Swift, because there is no conversion to NSArray.
If this was about specifically SKIE doing translations like here: https://skie.touchlab.co/features/flows#flow-translations Then it won't do it a level down, because while SkieSwiftFlow are Swift classes the FirstLevel and SecondLevel are not, so they're generic parameters must be object types.
j

Jan

11/09/2023, 8:06 AM
Interesting, I'll check out what you suggested, but that would make a lot of sense. Thanks for investing your time mate!
3 Views