Upon making my multiplatform SwiftUI app - I have encountered an issue when using ObservedObject between 2 views on macOS.
When passing an @ObservedObject in one view, to an EnvironmentObject in another this issue occurs only on macOS, iOS works fine
Any help is appreciated!
My code is here:
When passing an @ObservedObject in one view, to an EnvironmentObject in another this issue occurs only on macOS, iOS works fine
When modifying the entries variable, the array is updated as expected
This was verified by logging the addEntry and removeEntry calls
The sidebar containing the list however, doesn't update it's content
My app synchronizes this array with UserDefaults, after restarting the app the change is visible
Any help is appreciated!
My code is here:
Code Block struct EditView: View { @EnvironmentObject var settings: Settings @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode> var entry: ListEntry var body: some View { VStack { HStack { Image(systemName: "circle.fill") Text(entry.content) } .frame(minWidth: 0, maxWidth: .infinity, alignment: .center) .padding() Spacer() Button("Delete Entry") { settings.removeEntry(entry) presentationMode.wrappedValue.dismiss() }.padding() } .navigationTitle("Edit Entry") } } struct ContentView: View { @ObservedObject var settings: Settings = Settings.shared var body: some View { NavigationView { List { ForEach(settings.entries) { entry in NavigationLink(destination: EditView(entry: entry).environmentObject(settings)) { HStack { Image(systemName: "circle.fill") Text(entry.content) } .padding([.leading, .trailing]) .padding([.top, .bottom], 10) } } } .navigationTitle("Clipper") .toolbar { ToolbarItem(placement: .primaryAction) { Button(action: { settings.addEntry(ListEntry("Example Entry")) }) { Image(systemName: "plus.circle") } } } } } }