I have a List with rows which push a View. That view has another List which pushing another View. The original List, and the first pushed List will update when the data changes. However, the last view does not update when pushed. And when I swipe back the view no longer updates, even though it used to.
HomeView > UserView > ItemView
User and Item are structs which are Identifiable. I've tried making them Hashable and using id: \.self, but that didn't seem to work either.
class App: ObservableObject {
@Published var users = [User]()
}
struct HomeView {
@EnvironmentObject var app: App
var body {
List {
Section {
ForEach(app.users) { user in
NavigationLink(destination: UserView(user: user)) {
Text(user.name)
}
}
}
}
}
}
// Updates fine when `app.users` updates
// Stops updating after going back from ItemView
struct UserView {
let user: User
var body {
List {
Section {
ForEach(user.items) { item in
NavigationLink(destination: ItemView(user: user, item: item)) {
Text(item.name)
}
}
}
}
}
}
/// Does not update when app.users updates
struct ItemView {
let user: User
let item: Item
var body {
List {
Section {
ForEach(item.details) { detail in
Text(detail)
}
}
}
}
}
UserandItemand how/where do you update them? - Asperi