Starting to use <@U8NMFHUGJ>’s excellent-looking <...
# ios
d
Starting to use @kpgalligan’s excellent-looking SKIE 🎉 kodee loving - I've two questions about its Flows in SwiftUI feature: • Why is the Flow collection modelled as a View modifier? The function doesn't seem to be logically coupled with the view: We're 'just' collecting the Flow into a SwiftUI
@State
. Is this about narrowing the lifecycle of collection to only when that View is in the composition? • Example shows:
Copy code
// Collecting a flow into a SwiftUI @State property using a Binding, which requires the property to be of the same type.
        Text("Bound counter using Binding: \(boundCounter)")
            .collect(flow: viewModel.counter, into: $counter) // <----- Typo?
...but I don't see
$counter
defined - is this a typo and it should be
$boundCounter
?
k
Well, I'd say the brains behind SKIE belong to @Tadeas Kriz and @Filip Dolník. On
$counter
, does indeed look like a typo to me.
👍 1
blob ty sign 1
t
Hi, yes the
$counter
is a typo, should either be
$boundCounter
or the
boundCounter
property should be called
counter
. Thanks for bringing that up. As for the modifier, there are two ways to collect flows into SwiftUI, the
Observing
view and the
.collect
modifier. They ensure that the flow is being collected while the view is visible. If you need to collect a Flow outside of a SwiftUI view, for example in a ViewModel, you can use regular
for await
loop in Swift (https://www.hackingwithswift.com/quick-start/concurrency/how-to-loop-over-an-asyncsequence-using-for-await).