0

I have a problem where the master pane list view rows are not updating correctly in an iPad. I have reduced the code for description purposes to

struct CarsList : View {
    @State var isPresented = false
    @FetchRequest(fetchRequest: Car.allCarsFetchRequest())
    var cars: FetchedResults<Car>
    var body: some View {
        NavigationView {
            List {
                Button("Add Car") {
                    self.isPresented.toggle()
                }
                ForEach (self.cars) { car in
                    VStack {
                        Text ("List Car name: \(car.name!)")
                        NavigationLink(destination: CarDetailView(carVM: CarViewModel(car: car)) )  {
                            CarRowView(car: car)
                        }
                    }
                }
            }
        }
        .sheet(isPresented: $isPresented, onDismiss: { }, content: {
            CarDetailView(carVM: CarViewModel())
        })
    }
}

The iPad left pane shows a list of car names (CoreData managed objects). For test purposes, I show the name twice - in the Text(“List car name…“) and below the name is shown again in the CarRowView. The CarRowView has car: Car declared as an ObservedObject. I can tap on a row, to go to a detail view, where I can change the car name. When I do so, the List updates in that the Text(“List car name…“) shows the new name, but the CarRowView does not change. So changing the "car" in the detail pane, immediately shows in the List (in Text("List car name..") ) and yet even though that car object is sent to the CarRowView, where it is an ObservedObject, the CarRowView display does not change. The app uses CloudKit, and after I make the change, the new name appears ok on an iPhone (in CarRowView) running the same code. Any ideas why CarRowView would not update on the master pane of the iPad?

guinnessman
  • 433
  • 5
  • 15
  • Read for example [this](https://stackoverflow.com/questions/58643094/how-to-update-fetchrequest-when-a-related-entity-changes-in-swiftui/58777603#58777603) topic... and, in general, try to search - there are a lot of similar topics here – Asperi Nov 20 '19 at 07:33
  • Thanks that will be useful to read. However, I don't think there is a problem with the fetchrequest - the List does show the change to "car" in the TextView - and sends the changed "car" to the CarRowView, but the CarRowView isn't showing the change. – guinnessman Nov 20 '19 at 07:36
  • My iPad updated from 13.2 to 13.3 - and now it is working!! – guinnessman Nov 21 '19 at 15:25

1 Answers1

1

It looks like this was a SwiftUI bug and not a problem with the code as it now works with 13.3.

guinnessman
  • 433
  • 5
  • 15