In my SwiftUI project, I have a List, with each row representing a Core Data managed object, of entity Foo. Each row's View contains a ProgressView(), which I would like to have updated magically by binding to this property
@Published var doneness: Double
which I have added to class Foo. The Foo class itself conforms to ObservableObject, thanks to inheritance from NSManagedObject.
So, all the pieces are in place for SwiftUI magic to happen, except that I cannot figure out a syntax for wrapping the loop variable foo with @ObservedObject. This is, I believe, why my progress view is not updating – my body() getter does not get called as expected when a doneness value is updated.
The loop variable foo is declared in the ForEach, line 12. How can I make these observable objects?
I also tried to put the @ObservedObject wrapper on the array of foos, line 5, but the compiler did not like that either – Value of type 'FetchedResults<>' has no member 'wrappedValue'.
@Published var doneness: Double
which I have added to class Foo. The Foo class itself conforms to ObservableObject, thanks to inheritance from NSManagedObject.
So, all the pieces are in place for SwiftUI magic to happen, except that I cannot figure out a syntax for wrapping the loop variable foo with @ObservedObject. This is, I believe, why my progress view is not updating – my body() getter does not get called as expected when a doneness value is updated.
The loop variable foo is declared in the ForEach, line 12. How can I make these observable objects?
I also tried to put the @ObservedObject wrapper on the array of foos, line 5, but the compiler did not like that either – Value of type 'FetchedResults<>' has no member 'wrappedValue'.
Code Block @FetchRequest(entity: Foo.entity(), sortDescriptors: [], predicate: nil) var foos: FetchedResults<Foo> var body: some View { NavigationView { VStack { ... } List { ForEach(foos) {foo in HStack { ... if let doneness = foo.doneness { ProgressView(value:doneness) } } } } } }