https://kotlinlang.org logo
#touchlab-tools
Title
# touchlab-tools
с

Стефан Јовановић

11/12/2023, 7:43 AM
👋 Hey folks, I've just started experimenting with Skie, it looks like an amazing tool that will help us developers with KMP projects. I have a question, I've prepared a rather simple test example, but somehow I've been getting an error is Swift, when trying to use the flow: For-in loop requires 'any Kotlinx_coroutines_coreFlow' to conform to 'AsyncSequence' Shared part:
Copy code
class ProductApi {
    private val baseUrl = "<https://fakestoreapi.com/>"
    private val httpClient = HttpClient {
        install(ContentNegotiation) {
            json(Json {
                prettyPrint = true
                isLenient = true
                ignoreUnknownKeys = true
            })
        }
    }
    
    suspend fun fetchProducts(limit: Int): Flow<List<Product>> {
        return flow {
            // Delay to show a loading state.
            delay(2000)
            try {
                emit(httpClient.get(urlString = "${baseUrl}products?limit=$limit").body())
            } catch (e: Exception) {
                emit(emptyList())
            }
        }
    }
}
f

Filip Dolník

11/12/2023, 8:31 AM
Hi! There is a known bug in SKIE that prevents you from using Flows from suspend functions. (It will be fixed in one of the upcoming releases.) What’s little bit weird is that in my testing it caused a runtime crash not a compilation error. So one thing that I’d try is to make the
fetchProducts
non suspending - it doesn’t have to be suspending in your case.
If that doesn’t help then I’d start the debugging by verifying if SKIE is applied correctly. You can do that either by successfully using some other feature (like an enum) or by adding
print(Skie.self)
to the Swift code (assuming you are on a 0.5.x version) or by looking at the generated Swift code which is located in the
build/skie/$frameworkPath/swift/generated
👍 1
с

Стефан Јовановић

11/12/2023, 9:15 AM
@Filip Dolník Ohh right, I don't need it in my case here. Btw, I'm using Fleet IDE. Thanks for the quick response, I'll test it right away. 🙂
8 Views