Questions tagged [environmentobject]
120 questions
0
votes
1 answer
What is the difference between marking a variable with/without @Published in a class conforming observableObject?
everyone,
I'm currently working on a SwiftUI project and have encountered a question regarding the usage of @Published in a view model. I have a login view with a variable 'errorMessage' in the view model.
I noticed that even when I removed…

Rookie
- 21
- 2
0
votes
1 answer
Fatal error: No ObservableObject of type IconNames found. A View.environmentObject(_:) for IconNames may be missing as an ancestor of this view
I have created a class in SceneDelegate.swift file and I am trying to access it in SettingView.swift and ContentView.swift but I keep getting this error "Fatal error: No ObservableObject of type IconNames found. A View.environmentObject(_:) for…

Ansh Patel
- 15
- 5
0
votes
0 answers
Fatal Error using @EnvironmentObject in SwiftUI
import Foundation
import SwiftUI
import UserNotifications
class NotificationHandler: ObservableObject {
@Published var notificationCounter = 0
func askPermission() {
UNUserNotificationCenter.current().requestAuthorization(options:…
0
votes
0 answers
Change EnvironmentObject variable from onChange(of:) method
I have inProgress boolean variable in my models, which keeps track of active API requests like this:
class BranchListViewModel: ObservableObject {
@Published var inProgress: Bool = false
func setActive(success: (() -> Void)? = nil, failure:…

filip.karas
- 596
- 2
- 11
- 27
0
votes
0 answers
how to call a method in the @EnvironmentObject object instantiated in the view in the class AppDelegate class
When using applicationWillTerminate, which is executed when the application is terminated in swiftui, I want to call a method in the @EnvironmentObject object instantiated in the view, but I don't know how to do it. How should I do this?
class…

crept
- 1
- 1
0
votes
0 answers
How do I update my List using a ForEach on an EnvironmentObject?
I am trying to update a List using an availableModels array inside an EnvironmentObject. For some reason it doesn't refresh my view but I have no idea why. Very confused about this so help would be much appreciated, I'm new to SwiftUI and…

SkimoBen
- 19
- 3
0
votes
0 answers
Solved : How do I reset state of an ObservableObject without messing things up?
enter image description here
I have finally managed to resolve my issue. It was caused by depending on .onappear to set ObservableObject properties, rather than using an explicit prior user action with a button (for example).
This was the…

Paul Brankin
- 11
- 1
0
votes
1 answer
Unable to successfully connect ViewModel data to Table View
The Apple Documentation and all tutorials on Table usage that I've found (example 1 & example 2) build Tables from non-dynamic model arrays.
I have a ViewModel that contains a computed property array (userDataList) which utilized functions and…

weekendwarrior
- 85
- 8
0
votes
0 answers
Preserve ViewModel values when @EnvironmentObject value changes - SwiftUI
I am looking to preserve the viewModel.counter value even when valueComingFromParent value changes.
Right now, when Incrementer button is clicked it increments viewModel.counter value. But when Toast button is clicked, it changes value of a property…

Nabeel
- 841
- 1
- 10
- 23
0
votes
2 answers
"No ObservableObject of type found." (But I have included environmentObject already?)
So, I'm getting the following error:
SwiftUI/EnvironmentObject.swift:70: Fatal error: No ObservableObject of type AppViewModel found. A View.environmentObject(_:) for AppViewModel may be missing as an ancestor of this view.
However, I do actually in…

Kiarra J.
- 39
- 7
0
votes
1 answer
SwiftUI: View does not update with user input in Form fields/pickers
I can't seem to get my "Employee View" to update based on user input in the Form inside the "ProfileFormView." Currently any input in the Form fields does not affect the "EmployeeView". I need the data that is typed into the Form to update the…

weekendwarrior
- 85
- 8
0
votes
0 answers
Firebase App Sign Up Failure: Fatal Error - No ObservableObject of type AuthViewModel found
I'm building an app that uses firebase to authenticate users. I'm trying to sign up a new user and keep getting a fatal error. New to Swift so I'm probably missing something obvious.
Error: Fatal error: No ObservableObject of type AuthViewModel…

FlexBoxer
- 91
- 7
0
votes
0 answers
No ObservableObject of type found. environmentObject may be missing as an ancestor of this view
I'm getting this Fatal Error for the listViewModel. Do I add the @ObservableObject var listViewModel: MakeMyOwnListViewModel to the MakeMyOwnListView.swift or ManifestationMenuApp.swift file?
Thread 1: Fatal error: No ObservableObject of type…

Kraig Kistler
- 35
- 5
0
votes
1 answer
EnvironmentObject causes unrelated ObservedObject to reset
I am not quite sure I understand what is going on here as I am experimenting with an EnvironmentObject in SwiftUI.
I recreated my problem with a small example below, but to summarize: I have a ContentView, ContentViewModel, and a StateController.…

bjorn.lau
- 774
- 5
- 16
0
votes
0 answers
StateObject doesn't deinit when PhotosPicker was presented
I just do some experiments in my pet project on iOS 16 Beta. I noticed one possible memory leak. I created a simple project with simple steps which reproduce this behavior. So I have ContentView and DetailView I use NavigationStack for navigation. I…

Alexander Khitev
- 6,417
- 13
- 59
- 115