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

  Рет қаралды 5,998

Paul Hudson

Paul Hudson

6 ай бұрын

Download the completed project here: github.com/twostraws/hackingw...
Other parts in Project 14:
Introduction: www.hackingwithswift.com/book...
1. Adding conformance to Comparable for custom types: • Adding conformance to ...
2. Writing data to the documents directory: • Writing data to the do...
3. Switching view states with enums: • Switching view states ...
4. Integrating MapKit with SwiftUI: • Integrating MapKit wit...
5. Using Touch ID and Face ID with SwiftUI: • Using Touch ID and Fac...
6. Adding user locations to a map: • Adding user locations ...
7. Improving our map annotations: • Improving our map anno...
8. Selecting and editing map annotations: • Selecting and editing ...
9. Downloading data from Wikipedia: • Downloading data from ...
10. Sorting Wikipedia results: • Sorting Wikipedia resu...
11. Introducing MVVM into your SwiftUI project: This video
12. Locking our UI behind Face ID: • Locking our UI behind ...
Wrap up and challenges: www.hackingwithswift.com/book...
You can find the full set of videos, along with transcriptions, challenges, tests, and more, in my free 100 Days of SwiftUI course: www.hackingwithswift.com/100/...
Watch the full 100 Days of SwiftUI playlist here: • Understanding the basi...

Пікірлер: 14
@anotherguycalledsmith
@anotherguycalledsmith 5 ай бұрын
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 6 ай бұрын
@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.
@iLoveAppl3947
@iLoveAppl3947 3 ай бұрын
Use MVVM with Core Data for now. Look up the Router design pattern for SwiftUI which decouples navigation logic
@Contreras04
@Contreras04 2 ай бұрын
Man I wouldn't be an iOS developer if it wasn't for you. Thanks for all this content ❤
@peterhelms6839
@peterhelms6839 5 ай бұрын
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 5 ай бұрын
I'm here for those 2 beautiful dogs
@kimsanov
@kimsanov 7 күн бұрын
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?
@morrolan
@morrolan 2 ай бұрын
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.
@santhoshVnair
@santhoshVnair 3 ай бұрын
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?
@anudeepananth
@anudeepananth Ай бұрын
How would we share this viewModel across multiple views
@VitaliiTrofymenko
@VitaliiTrofymenko 5 ай бұрын
why do you have @State VM instead of @StateObject?
@anmolrajpalofficial
@anmolrajpalofficial 2 ай бұрын
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 Ай бұрын
`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 5 ай бұрын
What is this dog breed? They are adorable.
Learn the Essentials of Swift in one hour
58:14
Paul Hudson
Рет қаралды 177 М.
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 53 МЛН
THEY made a RAINBOW M&M 🤩😳 LeoNata family #shorts
00:49
LeoNata Family
Рет қаралды 34 МЛН
That's how money comes into our family
00:14
Mamasoboliha
Рет қаралды 10 МЛН
How to use SDWebImage in SwiftUI | Swift Packages #1
25:39
Swiftful Thinking
Рет қаралды 3,7 М.
Create your first app with SwiftUI and SwiftData
2:19:51
Paul Hudson
Рет қаралды 42 М.
Making it Rain - Advanced Special Effects with SwiftUI
29:16
Paul Hudson
Рет қаралды 14 М.
Write Better Code with Swift Algorithms
34:34
Paul Hudson
Рет қаралды 31 М.
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 32 М.
Syncing SwiftData with CloudKit - SwiftData SwiftUI Tutorial 5/5
8:29
SwiftUI Grids - LazyVGrid, LazyHGrid, Static Grid
17:55
Sean Allen
Рет қаралды 9 М.
Samsung Galaxy 🔥 #shorts  #trending #youtubeshorts  #shortvideo ujjawal4u
0:10
Ujjawal4u. 120k Views . 4 hours ago
Рет қаралды 3,8 МЛН
Собери ПК и Получи 10,000₽
1:00
build monsters
Рет қаралды 2,4 МЛН
iPhone 15 Pro в реальной жизни
24:07
HUDAKOV
Рет қаралды 204 М.
Mastering Picture Editing: Zoom Tools Tutorial
0:52
Photoo Edit
Рет қаралды 505 М.
Как слушать музыку с помощью чека?
0:36