Samuel
ok the one thing I don’t really get about SwiftUI is how it seems really easy to lose your scroll position. Like changing tabs or whatever wipes it out Do you really need to manually persist stuff like that? Seems very complicated. React Native just kinda handles it for you
1 2
Samuel
@samuel.fm
Yeah I’m probably doing it wrong but I don’t really get why
1
Kuba Suder 🇵🇱🇺🇦
I think some of the models that are keeping the data are not persistent between instances of the view and they need to use a different property wrapper so that they stay in memory with the data
1 1
Samuel
Oh so you keep the models above the view? Interesting. So for my list of feeds I’d have a model for each feed in an array or something?
1
Kuba Suder 🇵🇱🇺🇦
It's possible :D Ok, so just at quick glance, I haven't opened the project in Xcode: if you use @StateObject (or @State for simple values), that value/object is bound to the lifecycle of this view, and when you go out of it, the model is released)
1 1
Kuba Suder 🇵🇱🇺🇦
Which I *think* should be ok in this case for HomeViewModel, it would mean that TimelineViewModel would be released if you go out to the feeds list and it would reload the data when you choose Following again. To keep it you'd need to store it somewhere above and pass via environment or param:
What’s the difference between @ObservedObject, @State, and @EnvironmentObject? - a free SwiftUI by...
Learn Swift coding for iOS with these free tutorials
hackingwithswift.com
1 1
Kuba Suder 🇵🇱🇺🇦
If I understand the code correctly, I think the reason why HomeView[Model] also loses data when switching tabs might be that .task { } is basically .onAppear {}, so like viewDidAppear, so when you switch tabs it's called again and it reloads the data again, so you'd need to stop it from doing that
1