Debanshu Datta
12/19/2023, 8:57 PMdata class Success(val data: Flow<LocalAnimeEntity>) : AnimeLocalState
. I am using SKIE
to consume the flow (attached image of snippet). But I am getting this error log
error: generic struct 'ForEach' requires that 'SkieSwiftFlow<LocalAnimeEntity>' conform to 'RandomAccessCollection'
ForEach(successState.data, id: \.id) { anime in
^
SwiftUI.ForEach:2:15: note: where 'Data' = 'SkieSwiftFlow<LocalAnimeEntity>'
public struct ForEach<Data, ID, Content> where Data : RandomAccessCollection, ID : Hashable {
^
I tried to implement the example solution provided on the example in the docs, but is difficult to implement as I am not getting data directly.
Can someone help thank you colorkpgalligan
12/20/2023, 6:00 PMFlow
instance becomes an AsyncSequence
in Swift. They're logically similar, as is SwiftUI to Compose in many ways. I'm not a SwiftUI expert, but ForEach
looks like it takes a collection and cannot perform any async operations, which makes sense (that would be rather difficult in a declarative state-based UI system). Presumably Compose would present similar challenges. You'd probably want to collect all of the values on the Kotlin side into a List and use that instead of returning the Flow
and attempting to have the UI use that.
If it needs to be a flow, you'll need to loop over that in an async function and update some kind of observable state in Swift, which will redraw as new data is collected from the Flow
. Example here: https://github.com/touchlab/SKIEDemoSample/blob/main/ios/ios/ChatRoomDemo.swift#L49Debanshu Datta
12/20/2023, 6:07 PMTadeas Kriz
12/22/2023, 2:04 PMForEach
is a SwiftUI component that takes in an Array and runs the provided block for each item, thus creating a separate view for each item. We have a prototype for a component that's similar to ForEach
but instead of an array, you give it an AsyncSequence
and it runs the block for each item once it arrives. But it's not ready for release yet, so keep an eye out on our blog (https://touchlab.co/blog) where we'll post about it in the near future.Debanshu Datta
12/23/2023, 11:10 AMTadeas Kriz
12/23/2023, 5:02 PMFlow<Entity>
in Success
. What are you trying to model with the flow?