Questions tagged [environmentobject]

120 questions
0
votes
1 answer

I can’t get the array to update across all views despite using SWIFT playgrounds own code

I’m new so please forgive me. I’m following Swift Playgrounds tutorials on an iPad. They’re good but a little buggy. I’ve followed the tutorial. I should end up with code that shows 5 creatures, their name and emoji. I can press add to go to another…
0
votes
1 answer

SwiftUI EnvironmentObject does not redraw the current view but its parent view

I'm trying to understand how @EnvironmentObject affects redrawing when a property in ObservableObject changes. As per Apple's doc on EnvironmentObject, An environment object invalidates the current view whenever the observable object changes. If…
slow
  • 805
  • 3
  • 13
  • 27
0
votes
1 answer

I'm using @EnvironmentObject in SwiftUI and I got this "View.environmentObject(_:) for ViewModel may be missing as an ancestor of this view" Error

My code is something like this: class ViewModel: ObservableObject { @Published var value = "" } struct ContentView: View { @StateObject var viewModel = ViewModel() var body: some View { Group { if…
Ernest Tan
  • 11
  • 4
0
votes
1 answer

SwiftUI: @EnvironmentObject with ViewModifier?

Here is the idea of what I would like to do: my app's navigation contains a list, which displays a view on tap gesture which is triggered with a ViewModifier to perform an animation. In a nutshell: MyList > MyViewModifier > MyView Since I want to…
John DoeDoe
  • 133
  • 1
  • 7
0
votes
0 answers

SwiftUI: using colorScheme within EnvironmentObject

In our app, we have a basic colour palette used for the main design, however there is also the possibility for the user to choose their own colours via an admin system (for white labelling purposes). These colours are returned to us as hex strings…
DevB1
  • 1,235
  • 3
  • 17
  • 43
0
votes
1 answer

SwiftUI Child Views not updating as expected with environmentObject

Please see my example provided, I have recreated my pattern as accurately as possible while leaving out details that are not relevant to the question. I have @Published property variables in my viewmodel which are updated/assigned after a fetch to…
Andre
  • 562
  • 2
  • 7
  • 18
0
votes
1 answer

Recommended Way to Temporarily Store Text and Cursor Position for UITextView When Backgrounded

I have a UITextView with an attributedString for the text. When I either close and re-open the view or background the app and come back, the text in the textView disappears. I want to be able to temporarily save it until the user submits it. What is…
Connor V
  • 231
  • 3
  • 15
0
votes
1 answer

Swift/SwiftUI – Pass array to another view

I have a question regarding Swift where I just can't wrap my head around. I have a quite simple view. It's a list where you write down the name of each player and as soon as you hit return the name get's via onCommit appended to the array…
0
votes
0 answers

Using an ObservableObject singleton class for current session

I'm developing an IOS application on SwiftUI where a user can join groups and interact with other users, and I'm curious what the consequences of utilizing an ObservableObject singleton class for the current user's session are, which would directly…
corbiter
  • 47
  • 6
0
votes
1 answer

SwiftUI Image not showing a UIImage from variable

I want to display an image (type UIImage) which is stored in an EnvironmentObject. This EnvironmentObject consists of an array of a structure which holds an UIImage element. In a view, I want to display an image of this array but this doesn't work…
0
votes
1 answer

SwiftUI view is not updating from environmentObject observable property

I'm connecting a firestore database to my UI. I've created an SignedInAuthentication object which I set as an environment object class SignedInAuthentication: ObservableObject { @Published var user: User @Published var…
otusweb
  • 1,638
  • 1
  • 19
  • 30
0
votes
1 answer

Cannot preview this file - message send failure for display message to agent

Im having an issue using live previews on xcode. The project builds fine and works on a simulator. I have all my environmentobjects connected so I am a bit confused. And yes I also have the EO on the app file itself. "Cannot preview in this file -…
Trevor
  • 580
  • 5
  • 16
0
votes
0 answers

Cannot preview this file - message send failure

Im having an issue using live previews on xcode. The project builds fine and works on a simulator. I have all my environmentobjects connected so I am a bit confused. And yes I also have the EO on the app file itself. "Cannot preview in this file -…
Trevor
  • 580
  • 5
  • 16
0
votes
1 answer

SwiftUI: How to initialize a new StateObject in a parent view?

I have an app architecture similar to the below (simplified) code. I use a WorkoutManager StateObject which I initialize in the set up view, then pass down to its children via EnvironmentObject. The problem is that upon dismissing the .sheet there…
GarySabo
  • 5,806
  • 5
  • 49
  • 124
0
votes
1 answer

SwiftUi Extra Argument in Call When calling two views of @EnvironmentObject in main view

When calling one view environment object in main view thats ok build successful but when I call second view environment object its throw an error extra argument in call. struct mainView: View{ @EnvironmentObject var userInterestVM:…