Introducing MVVM into your SwiftUI project - Bucket List SwiftUI Tutorial 11/12

  Рет қаралды 10,558

Paul Hudson

Paul Hudson

Күн бұрын

Пікірлер: 17
@anotherguycalledsmith
@anotherguycalledsmith 11 ай бұрын
Dear Paul, This is pretty much the _most_ important video that you have published for a very long time! You might not think so, but for the self-taught average iOS/watchOS… programmer it is very difficult to properly organise larger projects. Of course, you would still like to keep some of your best tricks up your sleeves, but it is utmost helpful for all of us to see what goes where and what is best practise when it comes to app architecture. Please help us more how _not_ to end up in MVs (Massive Views). This extension tip is very useful and effective, thanks a lot!
@jur9103
@jur9103 Жыл бұрын
@Paul Hudson MVVM is nice, however as you said does not work with swift data nicely. What is YOUR opionion at this moment what app architecture would fit it better? I also like your comment at the end about experimenting. This help us move forward.
@Spacer-l3j
@Spacer-l3j 9 ай бұрын
Use MVVM with Core Data for now. Look up the Router design pattern for SwiftUI which decouples navigation logic
@nsuinteger-au
@nsuinteger-au 4 ай бұрын
How do you handle dependency injections for view models in a cleaner way
@Contreras04
@Contreras04 8 ай бұрын
Man I wouldn't be an iOS developer if it wasn't for you. Thanks for all this content ❤
@peterhelms6839
@peterhelms6839 11 ай бұрын
Excellent description on how to segregate model and view, I have been looking for a way to do it in SwiftUI as Views can grow very big with code attached inside. Thank you 🙂
@hazel_moonshine
@hazel_moonshine 11 ай бұрын
I'm here for those 2 beautiful dogs
@morrolan
@morrolan 8 ай бұрын
Hi Paul. I use this MVVM technique together with the .onAppear that will handle fetching data from API to populate a view. I have found that there are some use cases where .onAppear is not consistenly fired. In your example you are using init on the view model, but this is easy because you are not receiving any parameters. For example when I want to display this view for a product, I would pass the product id, which the onAppear will pass to the view model func loadData. Works great until onAppear doesn't fire.
@VitaliiTrofymenko
@VitaliiTrofymenko 11 ай бұрын
why do you have @State VM instead of @StateObject?
@anudeepananth
@anudeepananth 7 ай бұрын
How would we share this viewModel across multiple views
@kimsanov
@kimsanov 6 ай бұрын
What if i wanted further separate model from viewmodel. E.g. put saving and storing to Model class. What is best approach in this case? I'm confused whether Model should be injected in ViewModel? Or there is better approach?
@supersquare
@supersquare 3 ай бұрын
You're breaking the pattern. A data structure (model) doesn't include methods, it just describes the structure of some data. Utility methods should be placed elsewhere
@santhoshVnair
@santhoshVnair 9 ай бұрын
This scenario is nesting a class (ViewModel) inside a struct (ContentView). Will this create a problem in a document based app, where one might have multiple instances of the same view?
@supersquare
@supersquare 3 ай бұрын
Each view creates its own instance of viewmodel. if there are multiple view instances, they each have their own separate state. state cannot be shared between instances. for certain cases this seems nice
@anmolrajpalofficial
@anmolrajpalofficial 8 ай бұрын
I am confused. When I downloaded your project for final source code, it has @MainActor ViewModel of type ObservableObject but in your tutorial it's @Observable micro. In addition to that, I see you have changed @State viewModel to @StateObject viewModel in the ContentView. Can you please explain the reasons?
@tainc
@tainc 7 ай бұрын
`ObservableObject` and `StateObject` are the old way. If you are targeting iOS 17 or later, you should use `@Observable` and `@State` like he did in the video. At some point he'll update the sample code to match.
@tombruckner684
@tombruckner684 11 ай бұрын
What is this dog breed? They are adorable.
Learn the Essentials of Swift in one hour
58:14
Paul Hudson
Рет қаралды 210 М.
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
SwiftUI Fundamentals | FULL COURSE | Beginner Friendly
11:48:41
Sean Allen
Рет қаралды 396 М.
Create your first app with SwiftUI and SwiftData
2:19:51
Paul Hudson
Рет қаралды 57 М.
Programmatic Navigation in SwiftUI explained
17:50
donny wals
Рет қаралды 8 М.
SwiftUI MVVM Tutorial: Simple Example with ObservableObject
12:43
Logan Koshenka
Рет қаралды 21 М.
5 Steps to Better SwiftUI Views
31:19
Paul Hudson
Рет қаралды 56 М.
STOP Using MVVM with SwiftUI
18:30
azamsharp
Рет қаралды 17 М.
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН