Questions tagged [observableobject]
262 questions
1
vote
3 answers
How to initialize StateObject within SwiftUI with parameter
I'm working on a SwiftUI app using the MVVM architecture. I have the problem that I need to pass data from a parent View into its child viewModel, but I'm not sure how to pass a parameter from the view into the viewModel.
The child View which should…

Cameron Delong
- 454
- 1
- 6
- 12
1
vote
1 answer
Trying to set @published bool to true based on results from an API call
Hi first off I'm very new to swift and programing (coming from design field).
I'm trying to update doesNotificationsExist based on posts.count
I'm getting true inside the Api().getPosts {}
Where I print the…

Niklas
- 35
- 8
1
vote
2 answers
Check multiple @Published values
I have 3 classes:
class ClassOne: ObservableObject {
@Published var loading: Bool = false
}
class ClassTwo: ObservableObject {
@Published var loading: Bool = false
}
class ClassThree: ObservableObject {
@Published var loading: Bool =…

KScamorza
- 13
- 2
1
vote
0 answers
Thread 1: Fatal error: No ObservableObject of type SessionStore found
I receive the following error message: Thread 1: Fatal error: No ObservableObject of type SessionStore found. A View.environmentObject(_:) for SessionStore may be missing as an ancestor of this view.
Fatal error: No ObservableObject of type…

Nikola S.
- 82
- 7
1
vote
1 answer
Why is SwiftUI Binding for an array instance var not working?
Binding is not acting like expected and
I'd appreciate insights into what's going on.
Here's code that illustrates the issue. A class Model object called "Project"
contains an array of Strings called "name".
The code passes a Binding for name to a…

tdl
- 297
- 3
- 11
1
vote
2 answers
Calling functions in init() of SwiftUI View and ObservableObject
So I have a few data fetching tasks for views (type: View)that need to be run as soon as a view is loaded. If I put them in .onAppear{}, they don't load at the right time. So I must put them in the init(){} block of the struct.
Also, I have data…

Cayland Boston
- 79
- 2
- 9
1
vote
2 answers
My ObservableObject Class Array Variable 'timeStep' Fails To Hold Values
I have two ObservableObject classes: CarLotData and StopWatchManager. What I am trying to do is use my StopWatchManager class to load CarLotData property timeStep--which is a array Double type.
Here is my code for StopWatchManager:
import…

gosborne3
- 47
- 1
- 9
1
vote
2 answers
SwiftUI: ObservedObject/ObservableObject weird behavior
I recently encountered the following problem in SwiftUI with ObservedObject/ObservableObject:
If the ObservedObject/ObservableObject is publishing in a View, the body property is recalculated - as expected.
But if there is a sub View in the body…

lucaszischka
- 132
- 1
- 1
- 7
1
vote
2 answers
Data from ObservedObject not rendered in SwiftUI view
I use combine to connect to a REST API which pulls some data into an ObservableObject. The whole setup is really just MVVM. The ObservableObject is then being Observed in a view. Now, I'm stuck with a bug I can't seem to get resolved. What seems to…

DrGonzoX
- 363
- 4
- 14
1
vote
2 answers
Editbutton deletes items (with Bindings) from List in a funny way in SwiftUI
I'm giving up. Here's the problem: I try to load an array names as an ObservableObject in my List. The names must be connected as Bindings to the TextField:
class Users: ObservableObject {
@Published var names = ["Adele", "Taylor",…

J. Mann
- 115
- 6
1
vote
2 answers
Can't get SwiftUI View objects to update from @Published ObservableObject or @EnvironmentObject variables
I've done a ton of searching and read a bunch of articles but I cannot get SwiftUI to dynamically update the view based on changing variables in the model, at least the kind of thing I'm doing. Basically I want to update the view based on the app's…

Jordan
- 11
- 2
1
vote
0 answers
SwiftUI: How to publish a variable in a class member object (another instance of a class) and update UI in View
I have a class PlayAudio to read an audio file and play. In PlayAudio, I have @objc updateUI function to add to CADisplayLink. I have another class Updater where I initialize and control isPaused of CADisplayLink. I've instantiated @Published var…

deekay
- 35
- 6
1
vote
1 answer
SwiftUI View Not Updating to Environment Object
I am having an issue getting the ContentBodyView to update properly when a button is pressed in the MenuView.
When I print out the @Published currentPage var, it changes on button press, but doesn't appear to get carried across into ContentBodyView.…

cjochum
- 79
- 2
- 7
1
vote
2 answers
ObservableObject not updating View
I have created an Atimeter as ObservableObject, so that I can access it from several points in my App. Unfortunately the view is not updating, when the @Published variable pressure changes. Can somebody explain why?
I already tried {willSet…

Luke Crouch
- 107
- 6
1
vote
3 answers
Why @Published updates Text but doesn't update List?
I don't understand why the Text updates but the List does not.
I have a model with a @Published which is an array of dates.
There's also a method to generate text from the dates.
Here's a simplified version:
class DataModel: NSObject,…

Butterfly Ball
- 142
- 13