Quick question: For now, `fun suspendFlowFunction(...
# swift-export
g
Quick question: For now,
fun suspendFlowFunction(): Flow<String>
will create a
public static func suspendFlowFunction() -> any ExportedKotlinPackages.kotlinx.coroutines.flow.Flow
which loses its type (all generics are being transform into
(*any* KotlinRuntimeSupport._KotlinBridgeable)?
). So, if I need to type check, either I force cast in Swift or I’ll have to create a
fun suspendFlowFunction(callback: (String) -> Unit)
so that swiftExport translates to
public static func suspendFlowFunction(callback: @escaping (Swift.String) -> Swift.Void)
, but then it will make me collect the values inside Kotlin instead of Swift, am I correct? I know this is still in developing 😊 , just to check.
a
: Flow<String>
Interop with
Flow
is not designed and should be considered supported 🙂 If it works somehow on your side it's a coincidence, and it will be heavily reworked in the future. But yeah, if you want to write a "collect" method wrapper(so that you get some type-safety) - you should call the original collect inside that wrapper.
👍 1
g
I'm testing some scenarios and a simple data class I can force cast, but a List fails. Thanks for the info 😉
a
but a List fails
Yes, Lists(collections in general) are a special, same way as Strings, Closures and Primitives. We are currently focusing on coroutines support in general, so I don't have a timeline for you, when this quirk of the type system will be fixed(or if it's even fixable) 🙂
👌 1
g
Hello again 🙂
Copy code
suspend fun observeListOfMyClass(callback: (List<MyClass>) -> Unit) {...}
Copy code
public func observeListOfMyClass(
    callback: @escaping (Swift.Array<Swift.Never>) -> Swift.Void
) async -> Swift.Void {
    fatalError()
}
I guess even with callbacks,
List<T>
is out of the question for now 😅 , am I correct?
humm…. strange, I can make it work in other situation:
Copy code
public static func suspendFlowFunctionSpawn2(
    callback: @escaping (Swift.Array<ExportedKotlinPackages.com.playground.DataClass>) -> Swift.Void
) -> Swift.Void {
    return com_playground_suspendFlowFunctionSpawn2__TypesOfArguments__U28Swift_Array_ExportedKotlinPackages_com_playground_DataClass_U29202D_U20Swift_Void__({
        let originalBlock = callback
        return { arg0 in return originalBlock(arg0 as! Swift.Array<ExportedKotlinPackages.com.playground.DataClass>) }
    }())
}
ok found out my problem, ignore it 😅
K 1