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

Поділитися
Вставка
  • Опубліковано 4 лис 2024

КОМЕНТАРІ • 57

  • @AbelDemoz-v4m
    @AbelDemoz-v4m Рік тому +5

    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.

  • @xVinoz
    @xVinoz 10 місяців тому

    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.

  • @vebbis5961
    @vebbis5961 2 роки тому

    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.

  • @fubarhandle
    @fubarhandle 2 роки тому

    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.

  • @tsalVlog
    @tsalVlog 2 роки тому +1

    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.

  • @abrahamgonzalez1055
    @abrahamgonzalez1055 Рік тому

    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!

  • @alexsal6069
    @alexsal6069 Рік тому

    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

  • @amdizle28
    @amdizle28 Рік тому

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

  • @zaighamfarid9092
    @zaighamfarid9092 2 роки тому

    very simple tutorial.It is only for beginners

  • @russellwarwick
    @russellwarwick 9 місяців тому

    A great video! I see lots of people injecting the coordinator inside the ViewController or SwiftUI. Make views as dumb as possible only have an interface for input and output. The only small improvement I would make is the the naming of the callback from the view controller. Make the name agnostic to the navigation, it should be something like, didPressButton or didPressDetails e.t.c.
    Otherwise great video. 💙🚀

  • @scottwilson-billing7542
    @scottwilson-billing7542 2 роки тому

    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.

  • @applefan132
    @applefan132 2 роки тому +1

    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!

  • @__ale__
    @__ale__ 9 місяців тому

    Thank you for a great tutorial!

  • @kirandev1
    @kirandev1 5 місяців тому

    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.

  • @iamhome13
    @iamhome13 2 роки тому

    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.❤

  • @longchike
    @longchike 2 роки тому

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

  • @mistymu8154
    @mistymu8154 2 роки тому

    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.

    • @SwiftyPlace
      @SwiftyPlace  2 роки тому

      Thanks for the info! Good to know I am not the only one

  • @mckinneytravels8176
    @mckinneytravels8176 2 роки тому +2

    Nice tutorial on using coordinators, combine, and view models in UIKit with a bit of SwiftUI. Also I like the explanation of benefits of using Coordinator pattern (an ViewModels). I"ve used these patterns about three years ago in a commercial App (all UKit). What's your thoughts of using coordinators in a pure SwiftUI app (no UKIt)? Something I've just started to think about. Do you think the major issue is navigation?

    • @SwiftyPlace
      @SwiftyPlace  2 роки тому +1

      I am not sure how to implement the Coordinator pattern with SwiftUI. It is designed for UIKit. I did a test on the navigation for SwiftUI ua-cam.com/video/vL0w3kvng0o/v-deo.html. I really like to simplicity and state driven navigation. One of my main issues with SwiftUI is the navigation because in this area I cannot find nice work arounds for bugs. Also not much customisation: is it strange to ask for a way to change the font of a navigation bar title? This is probably a very common task.

  • @pheonix1371
    @pheonix1371 Рік тому

    Thanks this was really useful.

  • @ekucet
    @ekucet 2 роки тому

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

  • @GabrielAndrade-db6we
    @GabrielAndrade-db6we Рік тому

    Awesome video! There is only one thing that I don't really understand, why are we storing references to the child coordinators in the parent coordinator class ?

  • @k2d2258
    @k2d2258 10 місяців тому

    Thanks for the great video!

  • @Amerikkalainen
    @Amerikkalainen 2 роки тому

    This was fantastic - thanks!

  • @slmille4
    @slmille4 2 роки тому +1

    On the one hand this is a great way to get rid of the dependencies between views that NavigationLink creates by requiring an opaque type and get the navigation out of the VC...on the other hand it's going to huge pain in the ass if Swift projects are going to need UIKit navigation and SwiftUI views for the foreseeable future...

  • @filipenobrega6460
    @filipenobrega6460 2 роки тому

    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

  • @hashcat5721
    @hashcat5721 Рік тому

    Will there be a video on ELM architecture ?

  • @deepudaa8538
    @deepudaa8538 2 роки тому +1

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

  • @AndrewDChristie
    @AndrewDChristie 5 днів тому

    Thanks!

  • @wordpressmagics2613
    @wordpressmagics2613 4 місяці тому

    Hello. I have a question about childCoordinators property. I've tried to comment all the lines with this variable and everything works as it should. Why do we need it? Other guides and articles also implement some methods to remove childCoordinators from parent's array when popping from them. Can you explain it somehow? Btw, thank you for the video!

  • @yasindalklc5317
    @yasindalklc5317 4 місяці тому

    I just have one question. How we will manage rest of Coordinator if we want to pass from FirstDetailView to OnotherView? Do we have to create ViewController again every section or we can continue just with NavigationStack?

  • @daniyal2057
    @daniyal2057 2 роки тому

    Hi @karin Hope you are fine. Which one is better coordinator pattern or SwiftUi navigation which you showed in the last tutorial?

  • @eccentricyan
    @eccentricyan 2 роки тому

    thank you for the video. deinit coordinator is too difficult, so i choose viper router to handle the navigation...

  • @borjarodriguez5560
    @borjarodriguez5560 2 роки тому

    Thanks Karin for good content

  • @guitaripod
    @guitaripod 2 роки тому +4

    Thanks. It was interesting to see a different method of achieving a clear separation of concerns in SwiftUI 👍 Combine ftw
    Would you please consider using dark mode in the future? I'm watching these on a big screen, and light mode burns my eyes :D

  • @slmille4
    @slmille4 2 роки тому

    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

  • @JimGDawg
    @JimGDawg 2 роки тому

    I really like your approach. The only downside (and its pretty big) is you lose custom environment injection in SwiftUI (either custom environment keys, or environment objects). So I guess in your approach, you would hoist that data to a shared state singleton or thread it through the view hierarchy? I dont like either of those solutions, but I dislike SwiftUI navigation more : D
    Sidenote: really great stuff on your channel. I'm getting a lot out of it, especially as a UIKit dev coming to SwiftUI.

    • @andrejlotski
      @andrejlotski Рік тому

      Do you have a solution to this problem or think this can be solved by not ruining the concept of the Coordinator pattern?
      Also @Karin I would love to hear your thoughts on this.
      Great video and has really helped in my project.

  • @otniel2663
    @otniel2663 2 роки тому

    thankyou, great tutorial

  • @Kleczkovsky2r
    @Kleczkovsky2r 2 роки тому

    S tier content! :D

  • @ChrisHornberger
    @ChrisHornberger 2 роки тому

    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.

  • @yerihiturriago9271
    @yerihiturriago9271 2 роки тому

    Do you have tutorials for sales?

  • @kazakov708
    @kazakov708 Рік тому

    can someone please explain me how to transfer "hasSeenOnboarding" boolean state?
    i don't understand one thing :
    so in appCoordinator we create method which listen for the current state and depends on it load different flows: -
    1.if user launch application for the first time it's goes up for "onboarding" flow...okay but how do actually we change the state of it while user end up looking for onboarding instructions?
    I understand that Karin created observable object on appCoordinator, but which trigger change the state? She just pass this property inside " OnboardingCoordinator init() " And in start method simply put true inside this object.
    where we add target or some action on done button of OnboardingView?

  • @camilovargas1722
    @camilovargas1722 2 роки тому

    Thanks! I am just starting to learn Swift and this is incredibly useful.

  • @longchike
    @longchike 2 роки тому

    This might be a rare scenerio (and just a suggestion): can you add Objective-C view controller into this current structure, aka MVVM+C with SwiftUI View controller, UIKit View Controller, and Objective-C view controller? Some old project might be in the migration phrase and it does not tranalate its codebase to the Swift or SwiftUI fast enough.

  • @IannisSpiropoulos
    @IannisSpiropoulos 11 місяців тому

    I can't believe we're currently in SwiftUI 5 and NavigastionStack with NavigationPath is still problematic :|

    • @xVinoz
      @xVinoz 10 місяців тому

      good to see this comment, I just learned swiftui but havent done work with NavigationStack, Im aware of the problems it has cause ive been reading about it lol. Im gonna stick with UIKit for routing and SwiftUI for the rest

  • @rushibhatt4262
    @rushibhatt4262 Рік тому

    Great video Karin.. thank you for explaining the approach. Here instead of closers, isn't it better to just inject these coordinators inside the viewModels and then have those viewModels be injected in ViewControllers or Views. That way, from view or viewModel, we can directly call any methods on coordinators if need be,

    • @russellwarwick
      @russellwarwick 9 місяців тому

      No because you then cannot reuse the views as they have outside knowledge

  • @pheonix1371
    @pheonix1371 2 роки тому

    at 6:25 you say the recommended pattern is MVVM and then go on to explain MVC

  • @dimasai9845
    @dimasai9845 2 роки тому

    I guess better use Coordinators on Swift UI based

  • @HellkidScreams
    @HellkidScreams 2 роки тому

    Valeu!

  • @jacecrawford6015
    @jacecrawford6015 2 роки тому

    I can't believe more and more people don't reverse migrate back to UIKit. My time with swiftui was abysmal. I feel like it is still some time away from the standard for large projects

  • @GeovanniChavez-ht4gj
    @GeovanniChavez-ht4gj 5 місяців тому

    Those diagrams are so hard to understand…