Questions tagged [observedobject]

@ObservedObject is a SwiftUI property wrapper used to mark properties that are not owned by the View, but should update the View. Only ObservableObject conformant types can be annotated with the @ObservedObject property wrapper.

For more info, see the official documentation of @ObservedObject.

173 questions
2
votes
1 answer

Deleting CoreData Item which is also an @ObservedObject in DetailView causing App Crash in Swift 5

I am currently working with SwiftUI and CoreData. Situation: I have a User Detail View with a Delete Button. When pressed, the Core Data Entry of the User is getting deleted and the App Navigation goes back to the Root Navigation View, which is a…
christophriepe
  • 1,157
  • 12
  • 47
2
votes
1 answer

SwiftUI View not updating on async change to published properties of Observed Object

I have the following SwiftUI View: struct ProductView: View { @ObservedObject var productViewModel: ProductViewModel var body: some View { VStack { ZStack(alignment: .top) { if(self.productViewModel.product != nil) { …
Sebastian
  • 445
  • 5
  • 20
2
votes
2 answers

How to be notified of change to ObservedObject which conforms to a protocol

I'm building an AutoCompletion view and would like to pass an object which contains the field to be autocompleted. Currently I have two different types which I need to autocomplete on an attribute of, both attributes are named the same. I've created…
Houdi
  • 136
  • 10
2
votes
1 answer

SwiftUI pass by reference a class object to another view

I'm trying to learn SwiftUI and I'm going to develop a simple app with tab views and sharing core motion data between those views. The main idea is to create a motion manager object (like here) and use the sensor values in all…
2
votes
2 answers

SwiftUI @Published and @ObservedObject not going to NavigationLink destination

Sorry for the title and length I struggled to summerise I have a class of @ObserableObject @Published data which I want to change and use the new data on a second page accessed via NavigationLink class Data: ObservableObject { @Published var…
2
votes
0 answers

SwiftUI Is it possible to use Toggle to update value of ObservableObject

I have a date selector in a view and, once the user enters a date and saves I display a new view with a toggle. Ideally, once the users flips the toggle I'd like to be able to set a reminder using the date field already entered. I have created an…
BobdeBloke
  • 149
  • 1
  • 6
1
vote
1 answer

Changes to Observed Object not reflected (intermittently) when sheet is dismissed

I am using a class conforming to ObservableObject to store locations. I have used @AppStorage to persist an array of locations selected by a user. class SavedLocations: ObservableObject { @AppStorage("Locations") var all = [Location]() func…
John Harrington
  • 1,314
  • 12
  • 36
1
vote
1 answer

Saving state across views

I would like to implement a multi view questionnaire for the user to enter details about themselves. Therefore, I need a persistent storage about what the user picks preferably in an object that I can pass through different views which each mutate a…
1
vote
0 answers

@StateObject vs @ObservedObject in a UIKit parent environment

I have a banner component written in SwiftUI that I am embedding in a ViewController using a UIHostingController.view as a return type in a method: public static func createBannerView(thing: String) -> UIView? { let viewModel =…
Wesley
  • 5,381
  • 9
  • 42
  • 65
1
vote
1 answer

Is this the right way for using @ObservedObject and @EnvironmentObject?

Cow you give me some confirmation about my understanding about @ObservedObject and @EnvironmentObject? In my mind, using an @ObservedObject is useful when we send data "in line" between views that are sequenced, just like in "prepare for" in UIKit…
biggreentree
  • 1,633
  • 3
  • 20
  • 35
1
vote
0 answers

Environment dismiss provokes ObservableObject not publishing changes

I have a NavigationView which navigates to a first detail view. From this first detail view it navigates to a second detail view. In this second detail view I compose the UI observing a detailViewModel enum that stores the state: notRequested,…
rai212
  • 711
  • 1
  • 6
  • 20
1
vote
1 answer

Swiftui: List not displaying loaded data from viewModel

Hope you're well! I have an issue where updates to an array in my view model aren't getting picked up until I exit and re-open the app. Background: My App loads a view from a CSV file hosted on my website. The app will iterate through each line and…
Al McIver
  • 43
  • 1
  • 4
1
vote
1 answer

I want to click a button inside the First View and pass a Bool to the ContentView to show the secondView inside ContentView. How i can do it?

I make Observable class with Published var I want to click a button inside the First View and pass a Bool to the ContentView to show the secondView inside ContentView. How i can do it? The code in my First View is: class ShowPicker: ObservableObject…
Dmitry
  • 15
  • 4
1
vote
2 answers

SwiftUI: View does not fully update, lags behind when its @ObservedObject is updated from parent?

I have the following code: struct ContentView: View { @Environment(\.managedObjectContext) private var viewContext @State var selectedItemMOID:NSManagedObjectID? var body: some View { NavigationView { …
zumzum
  • 17,984
  • 26
  • 111
  • 172
1
vote
2 answers

SwiftUI NavigationView popping when observed object changes

There are three views. Main view, a List view (displaying a list of locations) and a Content view (displaying a single location). Both the List view and the Content view are watching for changes from LocationManager(GPS position). If the user…
Karlth
  • 3,267
  • 2
  • 27
  • 28
1 2
3
11 12