What is the correct way to share an ObservedObject between 2 views in SwiftUI?

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
  • 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

Is this a bug, or am I doing something incorrectly? I believe iOS is working because of the way the view is 'reloaded' when it comes back into view? - I'm really not sure.

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")
                    }
                }
            }
        }
    }
}


This is a multiplatform app (as described in Xcode), running on iOS 14 and macOS 11
If this is where you are creating your object and are only creating it once in a SwiftUI view, you should use the new @StateObject property wrapper.

Does this problem still persist if you use the following?
Code Block
@StateObject private var settings = Settings.shared


If this is where you are creating your object and are only creating it once in a SwiftUI view, you should use the new @StateObject property wrapper.
Does this problem still persist if you use the following?

Yes, it does
I must add, that when the list item is selected and the EditView is showing, the toolbar button also does not function, this is very odd
What is the correct way to share an ObservedObject between 2 views in SwiftUI?
 
 
Q