Questions tagged [environmentobject]

120 questions
0
votes
1 answer

How do you bind a list view

I have a CoordinateList view that shows a list of CoordinateRow views that have been entered, and are editable in place (in the list view). To add a new point to the list, the user presses a button at the bottom of the list, and it adds a row…
Sean Ogden
  • 158
  • 1
  • 7
0
votes
1 answer

Using EnvironmentObject to update existing list

I have an existing list, but I want to be able to add new items to it. Right now, I am using @EnvironmentObject, but when I add an element to the array, the view is not updated? I've seen solutions on the internet where you use …
i3ta
  • 11
  • 2
0
votes
0 answers

Geting EnvironmentObject into a class not in the hierarchy

I have a class that is used to get json data from a URL. I want to be able to change the path of the URL based on a property stored in an EnvironmentObject injected into the root view of my app. Apparently the class is not considered an ancestor of…
user1974376
  • 141
  • 1
  • 8
0
votes
1 answer

Error referencing EnvironmentObject in view initializer

I'm trying to reference an environment object in a SwiftUI view initializer to set up a state value, but I'm getting an error 'self' used before all stored properties are initialized. Is there a way to do this at all as you need to reference self to…
0
votes
1 answer

Show Selected ScrollView Item in Add New Item View SwiftUI

That is my projects link https://github.com/m3rtkoksal/TaskManager This is my TaskListView This is my NewTaskView Unfortunately when I tap one of the items in scrollview again I see an empty NewTaskView. I should see NewTaskView with selectedTask…
Mert Köksal
  • 817
  • 1
  • 7
  • 26
0
votes
2 answers

.onTapGesture Get Scrollview Item Data

My full project is here https://github.com/m3rtkoksal/TaskManager I have made SelectedTask an environment object as below let context = persistentContainer.viewContext let contentView = ContentView() …
Mert Köksal
  • 817
  • 1
  • 7
  • 26
0
votes
1 answer

Cannot convert value of type 'TaskElement' to expected argument type 'EnvironmentObject'

I have set my TaskElement model to be an environmentObject to be able to edit tasks. I did like this to be able to edit tasks on the same page to create a new task. Which is called NewTaskView. Btw, I also get an error in this NewTaskView_Previews…
Mert Köksal
  • 817
  • 1
  • 7
  • 26
0
votes
1 answer

Use ViewRouter in SwiftUI Project in Xcode 12

I tried to use this method (see link attached) in a new Xcode 12 project as a way to create a login page for a SwiftUI app, but I had the Problem not knowing what to add to the main App struct. I'm still a beginner and tried adding…
0
votes
1 answer

SwiftUI: EnvironmentObject loads only the first time

in my current project I work with an EnvironmentObject but I have a very strange bug, maybe someone can help. First the code: Model: class Daten: ObservableObject{ @Published var intervallInsgesamt: Double = UserDefaults.standard.double(forKey:…
Lukas
  • 251
  • 2
  • 13
0
votes
1 answer

How to bind data between views using @EnviromentObject?

I’m practicing how to bind data using @EnvironmentObject by making a simple practice app. The main view of the app is a simple list with a title in each cell. By clicking the cell, it will present the detail view. In the detail view is a TextField…
Byto H
  • 73
  • 8
0
votes
1 answer

Is there a way to Init CoreData AND EnvironmentObject in SceneDelegate?

how do I initialise both, the managedObjectContext and the .environmentObject in the scenedelegate root view ? I tried all variations of this code - it didn't work: let contentView = ContentView().environment(\.managedObjectContext, context) …
0
votes
0 answers

How to avoid Fatal error: No ObservableObject of type ... in SwiftUI?

I trimmed things down to this very simple example (a vanilla SwiftUI project, edit only ContentView and one line in SceneDelegate). Sets up a trivial ObservableObject and a couple of Views for screens. With latest Xcode 11.4 and simulator crashes…
James
  • 1,985
  • 18
  • 19
-1
votes
1 answer

SwiftUI Environment Object Not Getting Updated

I thought it was the case that @Published properties inside a class designated as an environment object would automatically update to all the subviews I pass the environment object to, but the below code isn't updating, what am I doing wrong? class…
GarySabo
  • 5,806
  • 5
  • 49
  • 124
-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
-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
1 2 3 4 5 6 7
8