Questions tagged [observableobject]
262 questions
-1
votes
1 answer
Thread 1: Fatal error: No ObservableObject of type SharedDataModel found. A View.environmentObject may be missing as an ancestor of this view
I have another project with almost identical code and it runs with no issues i'm not sure why it crashes. It build successfully then it crashes with Fatal error on the if statement line.
if sharedData.likedAwards.isEmpty {
…

Mxyb
- 83
- 1
- 9
-1
votes
2 answers
Data communication between 2 ObservableObjects
I have 2 independent ObservableObjects called ViewModel1 and ViewModel2.
ViewModel2 has an array of strings:
@Published var strings: [String] = [].
Whenever that array is modified i want ViewModel1 to be informed.
What's the recommended approach to…

Peter Warbo
- 11,136
- 14
- 98
- 193
-1
votes
1 answer
SwiftUI - Observable Object initiated from Swift class does not update @ObservedObject on ContentView()
The ObservableObject class is being instantiated from both the ContentView() as well as another Swift class. When a function of the ObservableObject class is run by the Swift class, it does not update the @ObservedObject of the ContentView().
I am…

Peanutsmasher
- 220
- 3
- 13
-1
votes
1 answer
Shared Data Model in Swift
Can ObservableObject be used in Swift? I only see tutorials for it in SwiftUI. I'd like to be able to load an object into memory from an API call. Then use VCs to manipulate different parts of it, and all subsequent VCs respond to it.

vazy
- 73
- 1
- 4
-2
votes
3 answers
Changing a `Published` property of an `ObservableObject` to a computed var
I have an ObservableObject with @Published properties:
class SettingsViewState: ObservableObject {
@Published var viewData: SettingsViewData = .init()
…
I would like to change viewData to a computed var based on other sources of truth…

Benjohn
- 13,228
- 9
- 65
- 127
-2
votes
1 answer
Compiler warning when setting up SceneDelegate for @EnvironmentObject
I'm trying to implement @EnvironmentObject to pass an array from a View in one tab to another view in another tab.
I get the yellow compiler warning:
Initialization of immutable value 'reportView' was never used;
consider replacing with assignment…

Tirna
- 383
- 1
- 12
-2
votes
1 answer
How to transfer data between Class/func and View
I decoded json data from an API and now I want to transfer the decoded data to my view where it can be displayed.
the problem is that I cannot transfer the decoded data to my view with @Observable Object.
My decoding class looks like this:
class…

Nicodimarco
- 1
- 1