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
0
votes
1 answer

SwiftUI Strange/unexpected behaviour when deleting elements in array of observedObjects

I am trying to create an editable 'parts list' in an app I'm trying to develop. It's been a rough road getting this far - many unexpected hurdles and obstacles, most of which have now been overcome (thanks to 'krjw'). So, I'm now at a stage where…
0
votes
1 answer

SwiftUI problem with UserDefaults in Model

I'm learning SwiftUI. I've started by doing Apple SwiftUI tutorials. In one of them they provided @EnviromentalObjects to make changes in their model, they were changing isFavorite bool state. But they did not use @ObservedObject with UserDefaults…
Maciekx7
  • 135
  • 1
  • 8
-1
votes
1 answer

Slide Show Dot Indicator - SwiftUI

I'm trying to build an image slideshow using Tab View with a custom Dot indicator based on UIPageControl but the dots are never displayed. Indeed the call to create the dot indicator is executed only once at the start of view creation The images in…
Arjun
  • 133
  • 1
  • 10
-1
votes
1 answer

SwiftUI Timer keep resetting when updating the ObservedObjects

I just made a simple code of a timer, and am trying to figure out a way to NOT reset the timer when other observed object status is changed. When I start the timer with init function, it resets whenever other observed objects' status is…
NARIO
  • 35
  • 1
  • 5
-1
votes
1 answer

Thread 1: Fatal error: No ObservableObject of type

Video Link Youtube ConsoleError Fatal error: No ObservableObject of type UserDefaultsConfig found. A View.environmentObject(_:) for UserDefaultsConfig may be missing as an ancestor of this view.: file SwiftUI, line 0 UserDefaults Config class…
Ufuk Köşker
  • 1,288
  • 8
  • 29
-1
votes
1 answer

Missing argument for parameter 'View Call' in call

I am struggle with understanding about why i have to give Popup view dependency named vm while calling this view since it is observable struct ContentView: View { @State private var showPopup1 = false var body: some View { …
Jef Codi
  • 1
  • 1
-2
votes
2 answers

SwiftUI: Set a Published value in an ObservableObject from the UI (Picker, etc.)

Update: This question is already solved (see responses below). The correct way to do this is to get your Binding by projecting the ObservableObject For example, $options.refreshRate. TLDR version: How do I get a SwiftUI Picker (or other API that…
Justin Reusch
  • 624
  • 7
  • 14
-2
votes
1 answer

Is this SwiftUI object being passed by value or by reference?

Consider a simple SwiftUI class to implement a countdown timer: class Stopwatch: ObservableObject { @Published var counter: Int = 0 var timer = Timer() func start() { self.timer = Timer.scheduledTimer(withTimeInterval:…
1 2 3
11
12