Post

Replies

Boosts

Views

Activity

Reply to How do I implement @StateObject in AsyncImage?
You'll have to change how ImageLoader is initialized as well. Make it default constructed and stored in a @StateObject, which it sounds like you already did. Next, instead of overwriting the state object in the view's init, delete the init entirely, and instead change the .onAppear() load call to pass the url. Here's a good antipattern rule to recognize: if you want to do something only once per view, it shouldn't be in the view's init. SwiftUI is creating a new flavor of the same view many times in reaction to events.
Jun ’20