Questions tagged [observableobject]
262 questions
0
votes
1 answer
watchOS didUpdateLocation freezes during location change
I am developing a running app in SwiftUI for watchOS. The problem is that when I start the run, the measuring works fine as 0.55 0.56 0.57 km, etc. Then it randomly freezes, and jumps from 0.57 straight to 0.71. Even the total distance is sometimes…

user7289922
- 181
- 1
- 11
0
votes
1 answer
Observed Object gets Dismissed Unintentionally SwiftUI
I have an HStack in a NavigationView with the following design:
User can scroll, then tap an item from the HStack list to see details
On Detailed View user can select the item
if item is selected, I place a new view of the selected item on top of…

TJMac
- 129
- 1
- 12
0
votes
1 answer
Missing arguments for parameters 'language', 'date' in call
I have an observable object:
class Schedule: ObservableObject {
@Published var language: Language?
@Published var date = Date()
init(language: Language, date: Date) {
self.language = language
self.date = date
…

Tirna
- 383
- 1
- 12
0
votes
1 answer
Swift fails to add another environment view
I have an environment object that works great but then I added another and when I put this last bit it gives me an error "Cannot use instance member 'brandViewM' within property initializer; property initializers run before 'self' is available" and…

Lloyd English
- 115
- 8
0
votes
1 answer
SwiftUI: How do i pass the value to another view?
What I am trying to do here is to pass the "KarvonenVal" to different View in another SwiftUI file. I have tried with .environmentObject and observableObject, but none of them worked. My goal is to display KarvonenVal on SummaryView. I appreciate…

Epicminetime
- 183
- 1
- 1
- 6
0
votes
1 answer
How to have a dependency set as a @propertyWrapper be a @ObservableObject?
I have a first @property wrapper that is made to be UserDefaults called @UserDefault(key: .isSignedIn, defaultValue: false) var isSignedIn: Bool. it is working fine as a publisher by using it this way, $isSignedIn to update my SwiftUI view when used…

Roland Lariotte
- 2,606
- 1
- 16
- 40
0
votes
1 answer
Text updating with ObservedObject but not my custom View
I am trying to code the board game Splendor as a simple coding project in SwiftUI. I'm a bit of a hack so please point me in the right direction if I've got this all wrong. I'm also attempting to use the MVVM paradigm.
The game board has two stacks…

user1357607
- 214
- 4
- 13
0
votes
1 answer
SwiftUI macOs AppDelegate detect the change of ObservedObject
I have the following AppDelegate class, I want to determine when userPreferences.backgroundIsTransparent changes state, must call a function inside AppDelegate.
I took a look here: https://stackoverflow.com/a/58431723/8024296
But I'm failing to…

Paul
- 3,644
- 9
- 47
- 113
0
votes
1 answer
Calling ObservableObject class initialiser to update List in SwiftUI
I have a List that is updated with a Fetch class, an ObservableObject. It has an init function. This is that Fetch class.
@Published private(set) var items: [ItemsResult] = []
init() {
let url = URL(string: "[redacted]")!
…

Noah64
- 89
- 6
0
votes
1 answer
SwiftUI - Use EnvironmentObject in ObservableObject Class/Dependency Injection
I am having trouble using an @EnvironmentObject in an @ObservableObject class. Based on some research, this is not possible, as EnvironmentObject is for views only.
I have resorted to doing the following, but the value is not updated…

nickreps
- 903
- 8
- 20
0
votes
1 answer
SwiftUI ObservedObject not updating parent view
I have 2 models: Bag and Food. A Bag contains 1 Food. The Food has a name.
I'm trying to bind the Food.name property with a TextField showed in the parent view (BagView) and another TextField showed in the child view (FoodView).
When I edit the…

Luca
- 25
- 4
0
votes
1 answer
How to bind an observable objects published integer variable to a textField in SwiftUI?
I have a viewmodel class like so:
class SharedViewModel: ObservableObject {
@Published var objectHeight: Int? = nil
}
and I am trying to bind to bind the variable to a textfield with a number formatter like so (the variable needs to be used…

Louis Davies
- 23
- 4
0
votes
2 answers
Fatal error: No ObservableObject of type SelectedTab found. A View.environmentObject(_:) for SelectedTab may be missing as an ancestor of this view
Getting error here - selectedTab = tab.getTab()
Fatal error: No ObservableObject of type SelectedTab found. A View.environmentObject(_:) for SelectedTab may be missing as an ancestor of this view.
Also tried this -…

vipinsaini0
- 541
- 1
- 7
- 26
0
votes
1 answer
Pass `environmentObject` data to another class (singleton)
I have an observableObject class that holds some data.
Observable Class
class UserManager:ObservableObject {
@Published
var profile:userProfileModel = userProfileModel()
@Published
var settings:Settings = Settings()
…

Mohammad
- 1
- 5
0
votes
1 answer
Can swiftUI ObservableObjects be instructed to modify themselves upon a data change event?
I would like to perform some assignments to some global variables when a change is made to an @Published item in an ObservableObject.
I have multiple @Published variables in my ObservableObject. Is there a way to adjust all the @Published variables…

gary
- 85
- 7