Swift Tutorial: How to use Coordinator Pattern with MVVM - Advanced Navigation in UIKit & SwiftUI

preview_player
Показать описание
In this advanced iOS tutorial I want to talk about the Coordinator pattern.
This pattern might be for you if you want to write a Swift app with a very flexible architecture which is modular and scalable.
I will show you a nice example with different app flow scenarios.
I use Combine to pass data between different Coordinators. I am also including MVVM (Model-View Model-View). In this demo project I will share the same view model between 2 different view/view controllers.
I will show how to programmatically show multiple different UIViewControllers together in a UINavigationViewController.
The data flow is done with the Combine framework because SwiftUI already relays heavily on it and I want to keep one with one consistent style.
I want to use both UIKit views and SwiftUI views to make the app architecture as flexible as possible.

Overview
00:00:00 introduction
00:06:09 MVC, MVVM and Coordinator pattern
00:13:29 Communication patterns: Combine
00:19:21 project setup
00:23:50 Coordinator implementation
00:49:03 data flow between Coordinators, view models and views
01:14:38 wrap up

Watch more

If you liked what you learned and you want to see more, check out one of my courses!
👩🏻‍💻 Combine course

#SwiftUI #iOSDevelopment
Рекомендации по теме
Комментарии
Автор

Precisely what I was looking for. The use of Combine fits well if you are listing to the Auth state and want to use coordinators.

vebbis
Автор

I just came over to a team that is in the process of planning to migrate their app to SwiftUI and Combine. Thanks for this! I'm still learning Swift (I have a C, Python and Kotlin background, so it's relatively familiar to me), but this is pretty close to a "middle-ground" for our current app and a full SwiftUI+Combine backend.

tsalVlog
Автор

Brilliant content. I'm an old Android dev who is branching off into iOS (Kotlin Multiplatform) and this is invaluable. I have been hearing about "Coordinator" for years but never looked into it. I thought it was some esoteric abstract way to compose application flows.

But it's literally the same pattern as our Fragment-based navigation, where Coordinator fulfills the same role as a Fragment! We have been using this for years in Android apps! Except we get this for "free" from Google as a part of their AndroidX library suite. This makes the switch all the more easy.

fubarhandle
Автор

Great video. Coordinators with Combine and MVVM are really powerful. Another approach would be to construct coordinators using factories, and delegate the responsibilities of navigation (e.g. pushing and popping) to a navigator class which gets injected into coordinators as a dependency.

ldtuwgv
Автор

This is beautiful! Just the way I would use SwiftUI and UIKit together. I think SwiftUI navigation really sucks and this is a great way to have "imperative" navigation while also making it declarative and reactive using Combine. I also like how these coordinators not only abstract away the navigation, but also handle data flow and act in a way as a "view factory". Fantastic concept presented in the best way possible. Also I really like the example you showed in the video - it's both simple enough to not overwehlm the viewer and complex enough to show off the concept properly and also see the benefits of having unidirectional dataflow. Fantastic! Keep up the good work!

applefan
Автор

Amazing content always using swift best practices along with great explanations and absolute understanding!!! Thank you!!!!

amdizle
Автор

Thanks for this imformative tutorial! Keep up with the good work, please!!!! ❤️

longchike
Автор

Amazing video, it's so well explained and helped me a lot to learn how to implement the coordinator pattern for navigation. Thank you so much ! :D

alexsal
Автор

Hey! Karin, , I just discovered your channel and you have really great content, you are a great teacher, i learned a lot with this video. Thanks for sharing your knowledge!

abrahamgonzalez
Автор

This is pretty straightforward; the only difference in all of this is having to use UIHostingController instead of just instantiating a VC as normal. It's cool to have all the power of the old and well tested coordinator pattern with the quickness of SwiftUI instead of having to code 100 lines to build a UI screen with UIKit. Haha.

xVinoz
Автор

yes, it is awesome video tutorial. Thank you for sharing your experiences.

ekucet
Автор

That was great thanks! We have been seeing inconsistencies with SwiftUI navigation in our Kotlin Multiplatform Application, which we finally solved using the Decompose library.

scottwilson-billing
Автор

Nice video, I had to do something similar in my project, I like swiftUI a lot due to the speed up that it gives, but some bugs is very annoying, other than that I see a lot of performance issues with SwiftUI as well, my solution was to use UIKit for top level on everything, this also avoid some random redraws

filipenobrega
Автор

This is a really interesting use of combine, but it seems like it would be much better to have the orientation flow as a modal under the navigation controller

slmille
Автор

MVVM is the same as MVC, just all the code from view controller goes in model view. It does not separate anything. MVVM replaces massive view controllers with massive view models. The only valuable thing Model View can do is to format model data. So it is good as two-way value transformers. But people just add complexity adding Combine, Coordinator and so on, that increases time for understanding such code.

kirandev
Автор

Oh my gosh. Your video is brilliant. I like it a lot. I just started coding and after this video I am definitely clear with Coordinator pattern. By the way use SWIFTUI with UIKIT is a brilliant idea.Thank you very much for this content. Like and subscribe.❤

iamhome
Автор

very simple tutorial.It is only for beginners

zaighamfarid
Автор

I have noticed a few bugs (some show-stopping) with SwiftUI navigation that would be inconsistent between iOS versions on the app I am working on. I also had to go back to using UIKit behind the scenes for navigation. This is definitely a more elegant solution than what I am currently using.

mistymu
Автор

Hey very helpful content as always 👌👌, can you please make a video on navigation between Swift Packages views using TCA.

deepudaa
Автор

Can you put up a link or show your code on your navigation that causes that second draw/navigate at the beginning (right side)? The only time I ever see that is when I break the basics of state updates, usually because I've made a horrible mistake in timing or nav-time updates to state. I'm just not sure how you got that to be a thing.

ChrisHornberger