There are lots of resources on how to use Flows fr...
# multiplatform
l
There are lots of resources on how to use Flows from Swift. Is there any info on how to create Flows?
😱 1
h
You want to implement the Kotlin flow interface in Swift? With all the callbacks and continuation objects and thread issues using the exported objective C API?
l
I have a domain interface that I would like to implement in Swift, which contains functions returning Flows.
h
But you could still use some Kotlin functions to create the flow and call it from Swift.
l
I can't seem to find emptyFlow(), flowOf(), mutableStateOf(), functions in the exported shared module in Swift. I have created my own proxies for now, but I wonder if there's a different approach. Maybe a way to convert Combine to Flow?
h
You have to export them:
export("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
in your framework in your gradle config. For example:
Copy code
val xcf = XCFramework()
    iosArm64 {
        binaries {
            framework {
                baseName = "shared"
                export("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
                xcf.add(this)
            }
        }
    }
But I would add some Kotlin helper methods that take some (suspend) lambda: () -> T and use it in a flow builder.
h
@Lukáš Kúšik Have you had any luck getting this to work? I'd also like to implement a function returning a Flow in Swift.
l
@humblehacker I just create a MutableStateFlow that I update using setValue from a Combine sink, after exporting the coroutines library to the shared Cocoapod. Not exactly the correct solution but it's a Flow 🤷 😄
102 Views