Questions tagged [environmentobject]
120 questions
0
votes
0 answers
How to use data from 1 tab view to another tab view in Swiftui? Looking for a approach
I have 2 tabs and the associated views are tabAView and tabBView.
On tabAView, 1 API call is there and got user object which is Published object in its ViewModel. ViewModel name is UserViewModel. UserViewModel is being observed by tabAView.
On…

user1960279
- 494
- 1
- 8
- 24
0
votes
1 answer
SwiftUI: Close modal sheet programmatically from a function inside an Environment Object
I've a main view that displays a modal sheet. As I've multiple modals, I use enum and State to control which sheet is presented.
@State var activeSheet: Sheet?
Inside my MainView:
Button(action: {
activeSheet = .settings
}, label:…

Mallon
- 13
- 4
0
votes
0 answers
Removing View with EnvironmentObject causes crash (SwiftUI)
I have an array of structs, which ForEach uses to generate SubViews. When I delete one of object from that array, one of SubViews disappear as expected. But when I pass an EnvironmentObject to the SubView and that view gets deleted, app crashes. By…

Jayåk
- 9
- 6
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
0 answers
Swift UI updating @EnvironmentObject prevent other update on @StateObject
I have the following view ModalView opened by by a parent view ParentView using a button in the toolbar
** Parent View **
import SwiftUI
struct ParentView: View {
@EnvironmentObject var environmentObject: MainStore
@State private var…

Cristian
- 1
- 2
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
How to solve this problem of "environment object"?
//environment object class
class AppData: ObservableObject {
@Published var studs : [StudentModel]
}
var body: some View {
VStack{
List(appData.studs,id:\.rollNo){ s in //causing error
…

Sidhan_T
- 3
- 1
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
Using ForEach(data:,content:) with an @EnvironmentObject in SwiftUI without resorting to trailing closure syntax?
I am refactoring my code, and want to use a memberwise initializer with ForEach(data:,content:).
I have a viewModel with an array of structs that conform to Identifiable:
class ViewModel: ObservableObject {
@Published var int = 0
var…

Kramer
- 338
- 2
- 15
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
SwiftUI using Environment Object on multiple views giving issues with Navigation
Don't know if I'm abusing the idea of environment object, but experiencing an issue when using an environment object that publishes a delayed async value. One view navigates to the next, but then the 'root' gets updated subsequently and as a result…

Mark Robberts
- 37
- 5
0
votes
2 answers
Can't Update Text on Previous View using @EnvironmentObject SwiftUI
i'm new in SwiftUI. So, I am doing my practice and create some kind of cashier app and here I been stuck for a while. In ProductPageView I can increase and decrease the number of item. Then, when I go to DetailOrderView (like a cart view), I can…

Aldo Sugiarto
- 197
- 3
- 20
0
votes
0 answers
SwiftUI: state passed to Child View not receiving updates?
I have a MasterView with a List.
By clicking on an item, the DetailView is displayed.
I am implementing this in the standard SwiftUI way, via the NavigationLink.
I am passing the detailState to the DetailView as a parameter.
I was expecting that…

Daniele B
- 19,801
- 29
- 115
- 173
0
votes
1 answer
How to setup an EnvironmentObject in SwiftUI without SceneDelegate?
I want to set up an EnvironmentObject in SwiftUI with the new App Protocol @main --> NO Scene or AppDelegate. Am I allowed to setup EnvironmentsObjects in my Content View, not my @main .swift ? And if yes? Why can't I pass in the environment Object…

Pit Kal
- 1