Linked Questions
17 questions linked to/from How to pass EnvironmentObject into View Model in SwiftUI?
0
votes
1
answer
795
views
@EnvironmentObject is passed after init is called [duplicate]
@EnviromentObject is passed down when the body is called, so it doesn't yet exist during the initialization phase of the View struct. Ok, that is clear. The question is, how do you solve the following ...
2
votes
0
answers
322
views
SwiftUI MVVM Pass EnvironmentObject into ViewModel [duplicate]
I have a view called FormView which has its own VM called FormViewModel. In this VM I have a method which adds a dictionary to Firestore. Alongside with some variables coming from the View, so from ...
489
votes
17
answers
418k
views
What is ViewModel in MVC?
I am new to ASP.NET MVC. I have a problem with understanding the purpose of a ViewModel.
What is a ViewModel and why do we need a ViewModel for an ASP.NET MVC Application?
If I get a good example ...
2
votes
2
answers
9k
views
How to inject a Model from the Environment into a ViewModel in SwiftUI
I am trying to MVVM my SwiftUI app, but am unable to find a working solution for injecting a shared Model from @EnvironmentObject into the app's various Views' ViewModels.
The simplified code below ...
4
votes
1
answer
2k
views
SwiftUI How to pass a global variable to non-View classes
I understand how to use @EnvironmentObject to make global data available to any view class, but I can't find a way to pass the variable to a non-view class.
My situation, which seems like a common ...
1
vote
4
answers
3k
views
Inject a StateObject into SwiftUI View
Can @StateObject be injected using Resolver?
I have the following:
struct FooView: View {
@StateObject private var viewModel: FooViewModel
some code
}
protocol FooViewModel: ObservableObject ...
2
votes
1
answer
1k
views
Cannot get @EnvironmentObject in Controller
I'm trying to use @EnvironmentObject to control some aspects of my app. The issue I'm having is that one of my controllers can't access the environment object. I get the fatal error "No @...
1
vote
1
answer
2k
views
Adding An EnvironmentObject to a ViewModel SwiftUI and MVVM
I am working with SwiftUI and am using MVVM with my VM acting as my EnvironmentObjects.
I first create a AuthSession environment object which has a string for currentUserId stored.
I then create ...
1
vote
2
answers
910
views
How to use @State to track the item to be add with Core Data in a sheet
I'm learning Core Data but a strange problem confused me at the very beginning. I was using the Empty project created by Xcode and did some modifications to try to implement the feature to add a new ...
1
vote
1
answer
1k
views
SwiftUI - MVVM - nested components (array) and bindings understanding problem
I just stuck trying to properly implement MVVM pattern in SwiftUI
I got such application
ContainerView is the most common view. It contains single business View Model object - ItemsViewModel and one ...
2
votes
0
answers
625
views
How to share an EnvironmentObject from a View to its ViewModel?
I'm using a DataStore environmentObject to pass data around my app, however I'm at a point where I needed to create a specific View Model class for a view, but I need to be able to pass the instance ...
0
votes
1
answer
552
views
Pass in default text in TextView while keeping state changes with SwiftUI
I am trying to set a default text on a TextView when the view appears, while being able to still keep track of changes to the TextView that I can then pass on to my ViewModel.
Here is a little example ...
0
votes
2
answers
683
views
View not reloading when @Published property is updated SwiftUI iOS15
I am trying to maintain an MVVM structure, and I've run into this issue where the view will show the value of the @Published variable one behind. The updated value will only be shown in View after I ...
2
votes
1
answer
188
views
@AppStorage property wrapper prevents from dismissing views
I have an app with four (4) views, on the first view I'm showing a list of cars pulled from CoreData, the second view is presented when a car is tapped and it shows the services for each car. The ...
0
votes
2
answers
245
views
SwftUI List storing style in the model
I am storing the list's style into the ViewModel as shown in the code below.
class Model: ObservableObject {
@Published var items = ["A", "B", "C", "D"]
...