Advanced Coordinators in iOS

  Переглядів 40,581

Paul Hudson

Paul Hudson

День тому

In my previous coordinator video we covered the basics of building an iOS app using the coordinator pattern. In this follow-up video I address six common questions that I get asked about coordinators:
- How and when do you use child coordinators?
- How do you handle moving back from a navigation controller?
- How do you pass data between view controllers?
- How do you use tab bar controllers with coordinators?
- How do you handle segues?
- How do you use protocols or closures instead?
Just like the first video there's lots of live coding so you can see exactly how each problem is solved - if you use the coordinator pattern in your apps you should hopefully find lots to learn here.
If you missed my previous coordinators video, watch it first: • How to use the Coordin...
I'm really grateful to Soroush Khanlou (khanlou.com) for taking the time to record a segment in this video. He's been working on this pattern for four years now, and continues to refine it.
I've published articles on coordinators you might find useful:
- How to use the coordinator pattern in iOS apps: www.hackingwithswift.com/arti...
- Using closures with the coordinator pattern: www.hackingwithswift.com/arti...
- How to create a custom Xcode template for coordinators: www.hackingwithswift.com/arti...

КОМЕНТАРІ: 69
@VAIBHAVMISRA1987
@VAIBHAVMISRA1987 4 роки тому
Thank you Paul. Every one of your video is immensely helpful and extremely practical. I definitely feel I'm a better engineer after watching your videos and trying them out in my projects.
@ragnacode56
@ragnacode56 4 роки тому
Every time I enjoy your tutorials! This one was awesome! Thank you!
@emilmicu9528
@emilmicu9528 4 роки тому
Great insights, thanks for sharing. I'm using a similar approach, but instead of holding a reference to the coordinator I use a navigation delegate protocol for higher decoupling. This way the VC just informs the coordinator that the buy button was tapped instead of calling `buySubscription()`. So basically the VC knows only about itself and nothing else.
@yonataan8
@yonataan8 4 роки тому
Thanks for your great tutorials Paul! You're great!
@shriyamgupta8217
@shriyamgupta8217 Рік тому
This is truly the best explanation out there for Coordinators in iOS! Thanks Paul!
@ParthoBiswas007
@ParthoBiswas007 3 роки тому
I have been following your tutorial recently and I love it. FUN, Informative, and Concise.
@daniltimofeev6566
@daniltimofeev6566 3 роки тому
It is really fun, especially when you want modal presentation =)
@komunamu
@komunamu 4 роки тому
Thank you Paul for your great tutorial. When we use the coordinator with tabbarcontroller, what is the best way to add the login screen?
@jconstant
@jconstant 5 років тому
Paul, these coordinator videos are fantastic. Thank you! I want to use a coordinator to manage multiple view controllers but in my case, I don't want those view controllers to fill the entire screen when shown because I have a search bar at the top of the screen that should always be displayed. Can this pattern be used to swap view controllers in/out of a Container View?
@user-sn1st4lm5w
@user-sn1st4lm5w 4 роки тому
Thanks for great tutorial, Paul! But I wonder what is the right way to present controller using coordinators? In video code examples you only push view controllers, what if we need to present controller modally?
@t16incho
@t16incho 5 років тому
UKposts would invent a new super mega like button just for this video. Thanks Paul.
@amitsamant3875
@amitsamant3875 4 роки тому
Hey paul, great explanation. I have a doubt regarding how to separate networking while using coordinator. for example the BuyViewcontroller takes the product id to buy and the product id has to be fetched from the network on basis of the selectedSegmentIndex so where should we trigger the network call inside the ViewController or Inside the coordinator?
@rajatmishra8121
@rajatmishra8121 4 роки тому
Hi Paul, Great video. Thanks for sharing. Learn alot from this tutorial Could you please let me know on what basis should we create sub-coordinators in the app? I mean if we have Login Flow, Home Screen Flow then should we have 2 sub coordinators for them or is there any other factor to consider while considering sub-coordinators? Thank again
@Sin00b
@Sin00b 5 років тому
I quickly converted my project to coordinators, and it makes me very happy to split out the navigation from my controllers. My app uses a singleton for networking (I know you don’t like singletons, but I feel like for simple networking across a bunch of views, it actually makes sense, but am open to feedback), and coordinators to move between the different views, usually via button press. I can’t wait to convert over to child coordinators so i can use them in a tabviewcontroller and decouple different tabs out. It’s super clean, thanks for sharing. (BTW, I’m using server side swift for the networking as well, so thanks for teaching me vapor... its a doozy)
@rikenm
@rikenm 5 років тому
singleton is fine if there is no state in the singleton class. Networking has no internal state usually.
@DimaJP
@DimaJP 4 роки тому
Clear and interesting - very good material.
@alexl2512
@alexl2512 2 місяці тому
This is a great video worth watching multiple times.
@byaruhaf
@byaruhaf 5 років тому
Definitely one of the best videos on the Coordinator Pattern topic! Really enjoyed watching it! Great job, Paul & Soroush!
@chamorro858
@chamorro858 5 років тому
Awesome job Paul, thank you for covering a lot of coordinator questions that don't seem to be answered on other coordinator tutorials!
@TheScrinn
@TheScrinn Рік тому
Hi, thank you for video. I repeat everything what you did but I barely understand how to implement this by myself from scratch. What can I do to understand it better ?
@arekw6012
@arekw6012 3 роки тому
Great video! But how to implement a modally presented date picker? When user selects a date from presented view controller, the date must back to the caller. How to do that?
@bscheirman
@bscheirman 5 років тому
Great job Paul! This covers most of the scenarios I've found people ask about when talking about coordinators as well.
@bdaralan
@bdaralan 5 років тому
Thank you for a great explanation. Will implement this in my current senior project app.
@pierogfgenoveseII
@pierogfgenoveseII 5 років тому
Great video!
@Paul-tg8pq
@Paul-tg8pq 2 роки тому
Thank you for your video! this video is very helpful to me. I have some questions. I can't understand why childCoordinator array exist. Actually, It just added and deleted a coordinator from itself. It doesn't play a role to perform related to transition and so on. When does it use? Why do you use array instead of Dictionary? If we have to use coordinators in array, this is not useful to find and access at once. please, answer my question...
@alexkiddens2199
@alexkiddens2199 5 років тому
1. Child coordinators - ukposts.info/have/v-deo/rZVzrZhnhHh-smg.html 2. Navigating back - ukposts.info/have/v-deo/rZVzrZhnhHh-smg.html 3. Passing data between controllers - ukposts.info/have/v-deo/rZVzrZhnhHh-smg.html 4. Coordinated tab bars - ukposts.info/have/v-deo/rZVzrZhnhHh-smg.html 5. Using segues - ukposts.info/have/v-deo/rZVzrZhnhHh-smg.html 6. Protocols and closures - ukposts.info/have/v-deo/rZVzrZhnhHh-smg.html
@xfabiosoft
@xfabiosoft 4 роки тому
Some video/tutorials about ReSwift and redux on ios?
@user-bn5xz3ed9d
@user-bn5xz3ed9d Рік тому
Thank you Paul 😄
@TheVirusRko
@TheVirusRko 4 роки тому
Who should handle the navigation bar behaviour? For example if we want the nav bar to be hidden in our "main" or first viewcontroller but when we move to another flow we want to show it? Should it be on every VC? or this must be handle by the coordinator again?
@alikiran7329
@alikiran7329 4 роки тому
So, what's the value of keeping child coordinators in an array and removing them on way back? Navigation controller (actually any parent controller) already tracking child controllers. We can access the relating child coordinator using childcontrollers anyway.
@charliesoandso
@charliesoandso 5 років тому
Oh, I love the tab bar integration. Great video as usual, Paul.
@zarzonis
@zarzonis 5 років тому
Awesome explanation on these topics Paul. From now on, I’ll use coordinators.
@deborabarbosa9646
@deborabarbosa9646 4 роки тому
Is there a way of nagating back with only the mainCoordinator and those 3 viewControllers? (without childCoordinators)
@robtea3941
@robtea3941 4 роки тому
Interesting, so say I wanted 2 tabs, I would make another coordinator similar to MainCoordinator and add its nav controller to the tabbar viewcontrollers array. In that case every tab had its own instance of UINavigationController. Also, say a tab just had a single view controller, I wouldn't bother with a coordinator in that case and just add it directly to the tab bar viewControllers array
@gabrielsscavalcante
@gabrielsscavalcante 5 років тому
Thank you again! Great video! I was waiting for this one :)
@ocannal
@ocannal 3 роки тому
Hello Paul, I think there is problem with the navigating back approach. Let's say we push another viewcontroller in BuyViewController. So didshow will be called again and from controller is BuyViewController, and it will be removed even it's not expected. It's not expected because it's not the child this time, it's parent previous viewcontroller and it's still in the viewcontroller hierarchy.
@jakyducati
@jakyducati 5 років тому
closures fit just great here
@burakakyalcin
@burakakyalcin 5 років тому
yeah but i don't like them taking too much space
@akshitzaveri224
@akshitzaveri224 4 роки тому
When you have many actions, closures degrades the readability and maintanability.
@daisoreanulaurentiu3943
@daisoreanulaurentiu3943 Рік тому
Hi Paul, shouldn't we also use a protocol between MainCoordinator and BuyCoordinator?
@maximkrouk1697
@maximkrouk1697 5 років тому
Love the content you do ❤️, definitely gonna buy a few books soon c:
@harrylee3943
@harrylee3943 2 роки тому
The best resource to learn coordinator pattern. I've watched this more than 10 times. This might be a silly question but I am not really sure why we need to keep array of child because in this video, the usage of the array is to just append when child runs and remove when child stops. Can anyone help me to understand?
@aleph.5811
@aleph.5811 4 роки тому
so in the child coordinator section, who is responsible for calling buySubscription()? Also, in the BuyViewController, how is it possible to instantiate the navigation stack which needs to reference to what the UIWindow is referencing?
@goatfacethrilla9367
@goatfacethrilla9367 3 роки тому
Should each coordinator only push a single view to the navigation stack? If another view is required should the coordinator start a coordinator for THAT new view instead?
@frantisaulhuamanmera3126
@frantisaulhuamanmera3126 5 років тому
thanks for sharing Paul.
@kohjiarong6452
@kohjiarong6452 5 років тому
Hi Paul, thanks for providing explanations. It would be great if you could also explain how can we use coordinators to handle different size variants, ie iPad and iPhone variants. Thanks!
@oguzparlak7857
@oguzparlak7857 5 років тому
Great Job Paul ! It helped me a lot.
@emashawn3734
@emashawn3734 5 років тому
Absolutely right about Segues. Although i use storyboards most of the time but i don't use segues as it tightly couples the flow.
@jeraldo4571
@jeraldo4571 3 роки тому
Should coordinators be on the ViewControllers or it should be owned by the ViewModels?
@nickkarpov1
@nickkarpov1 3 роки тому
Awesome!
@estiqueahmedrashel2279
@estiqueahmedrashel2279 3 роки тому
How to handle back when we want to go to a different ViewController from BuyViewController?
@jevoncharles606
@jevoncharles606 5 років тому
Great video. You have the ability to take something that can be complicated but make it seem simple. I notice that coordinators are a big topic in the community right now. I do like the upsides to them. Do you ever fear there is too many ways that are considered good coding but all do the same thing?
@abdullabardiyev299
@abdullabardiyev299 Рік тому
what does "Control the flow in your app" mean if someone knows please help me
@serhatt
@serhatt 5 років тому
When I first saw coordinator I thought it's a good solution for navigation hell. But for this implementation, it adds another complexity into the code base. There are lots of closures, parent-child references going on, another problem is handling the back button. It's kinda good solution to adding removing from an array but when the project grows it won't be flexible and scalable also conforming navigation delegate also adds another complexity for every view controller transition developer should add another if statement for that. In my opinion, the coordinator pattern is not a good solution for navigation instead of solving navigation problem it adds another overhead. If I'm wrong please let me know I may have misunderstood the concept in the first place!
@rikenm
@rikenm 5 років тому
I have seen people do a binary search instead of linear search to improve the performance. Closures are optional.
@leftboot13
@leftboot13 5 років тому
I programmatically create my app and use child viewcontrolers. If I understand correctly, I don’t need to worry about implementing “storyboarded”. Is that right? How would you go about configuring a cordinator for this? Create a main coordinator and let all the child view controller‘s talk to that coordinator? Then pass the data as shown? Thanks for the great info once again.
@davidhughes9320
@davidhughes9320 5 років тому
How do you present view controllers? This only shows how to push and use navigation controllers. A common case might be presenting a UIAlertController.
@ahmedabdallah741
@ahmedabdallah741 4 роки тому
I thought about it and I hope there is a good answer. I solved it by passing the viewController and make the present from the coordinator func buyAnAccount(_ viewcontroller: UIViewController) { let vc = BuyViewController.instantiate() vc.coordinator = self viewcontroller.present(vc , animated: false) }
@abanoubghaly7685
@abanoubghaly7685 2 роки тому
Can anyone tell me the benefits of using an array of child coordinators because I just append and remove them without using their references in the navigation process itself Anyone could help?
@SteveHiemstraAKAspeg
@SteveHiemstraAKAspeg 3 роки тому
So glad I only know SwiftUI.
@rgenericson5361
@rgenericson5361 3 роки тому
Then you're seriously missing the boat bro! ; -)
@shadealix
@shadealix 2 роки тому
Making any coordinator to be UINavigationViewControllerDelegate has huge cons. Any coordinator which has reference to navigationController can re-assign delegation to itself at any time. And it's brake the logic
@felipefgarcia8969
@felipefgarcia8969 5 років тому
Why not have a sample project so we can download and see the implementation, there's no link to github or something like?
@WilliamGattoFilho
@WilliamGattoFilho Рік тому
3:16
@salmansiddiqui299
@salmansiddiqui299 5 років тому
How to pass data from one coordinator to another?? As we are using common coordinator protocol to start
@khongduocbocuoc
@khongduocbocuoc 4 роки тому
How to handle coordinator if I present ViewController instead of push it
@EEGAMINGYT1994
@EEGAMINGYT1994 5 років тому
I am first person to view this video thanks for the video
@xVinoz
@xVinoz 7 місяців тому
ahhh the excessive zoom in the screen is driving me crazy
@xVinoz
@xVinoz 7 місяців тому
If you are using storyboards stop and start programatic uikit, thats the industry standard, peace.
How to use the Coordinator pattern in iOS
18:12
Paul Hudson
Переглядів 70 тис.
Teenagers Show Kindness by Repairing Grandmother's Old Fence #shorts
00:37
Fabiosa Best Lifehacks
Переглядів 11 млн
😱СНЯЛ ФИКСИКОВ НА КАМЕРУ‼️
00:35
OMG DEN
Переглядів 1,4 млн
How to implement the Coordinator pattern in Swift!
11:24
Vincent Pradeilles
Переглядів 8 тис.
Coordinator pattern in iOS Swift Part 1 | Hindi tutorial
19:16
Code Cat
Переглядів 10 тис.
8 Common SwiftUI Mistakes - and how to fix them!
28:05
Paul Hudson
Переглядів 49 тис.
Why I don't do MVVM anymore
10:56
Flo writes Code
Переглядів 6 тис.
24 Xcode Tips in 15 Minutes
15:30
Paul Hudson
Переглядів 72 тис.
HUAWEI БЕЗ GOOGLE: ЕСТЬ ЛИ ЖИЗНЬ? | РАЗБОР
11:49
RTX 4070 Super слишком хороша. Меня это бесит
15:22
Рома, Просто Рома
Переглядів 93 тис.
КУПИЛ SAMSUNG GALAXY S24 ULTRA ЗА 88000 РУБЛЕЙ!
27:29
DimaViper
Переглядів 66 тис.