[sample code]when model changed, the view in SwiftUI isn’t update

in the SampleTrips, for the pure SwiftData version, when I add a living accommodation from the trip detail view, the trip detail view won’t update until I go back to the trip list view and enter again.

why didn’t the trip detail view update?

I have tested the pure CoreData version in sample code, it worked well.

is this a bug or a feature of SwiftData?

Answered by taofuns in 790394022

The solution is changing newLivingAccommodation.trip = trip to trip.livingAccommodation = newLivingAccommodation. After one year, Apple haven’t change this in their sample code.

Accepted Answer

The solution is changing newLivingAccommodation.trip = trip to trip.livingAccommodation = newLivingAccommodation. After one year, Apple haven’t change this in their sample code.

[sample code]when model changed, the view in SwiftUI isn’t update
 
 
Q