How to use the Coordinator pattern in iOS

  Переглядів 70,020

Paul Hudson

Paul Hudson

5 років тому

The coordinator pattern takes responsibility for navigation out of your view controllers and into a separate class, helping you make your view controllers smaller and simpler.
In this video I'm going to explain the problem coordinators solve, walk you through the code required to use them, then give a complete coding demo with a new Xcode project.
Coordinators were pioneered on iOS by Soroush Khanlou - he does tweet from time to time at @khanlou, but really you should check out his blog at khanlou.com.
I've also 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...

КОМЕНТАРІ: 176
@mustafa521996
@mustafa521996 5 років тому
A brilliant video, such clarity! Whenever you import UIKit, Foundation is no longer required as UIKit already imports Foundation! You'd know this but others would learn from you :)
@RobertHolzapfel
@RobertHolzapfel 5 років тому
Dear Paul, thanks so much, this is one of the best material (for more advanced programmers interested in architecture, design patterns) you ever made. I am so grateful. I tried once to implement the coordinator pattern, but struggled due to the mutual dependencies. You made it completely clear to me in this video. You saved my day! Thanks god for making you a SWIFT lecturer. 👍🏻
@devbenomad2393
@devbenomad2393 5 років тому
I've been following your content on HWS for a long time now, You are the best Paul ! No competition REALLY , among the too many good iOS teachers I know you can easily stand out because of your true understanding of apple's frameworks and tools. You provide clear and COMPLETE content. I'm gonna tell all my friends about and tell them to subscribe ;)
@twostraws
@twostraws 5 років тому
That's very kind of you - thank you for the generous words!
@prakashinani708
@prakashinani708 4 роки тому
Great Video Paul. Explained in easy way. I am new to iOS and looking forward to your live app session.
@reymundopanaguiton6320
@reymundopanaguiton6320 5 років тому
Wonderfully done. This solves a lot of horrendous amount of task just to navigate from one scene to another. Absolutely Brilliant... I love this.
@srinathshah7461
@srinathshah7461 4 роки тому
A good overview for the Coordinator Design Pattern! Thumbs up!
@kastor8274
@kastor8274 5 років тому
This is the 1st video of you I watched... AWESOME ! Thanks a lot
@fgary
@fgary 5 років тому
An awesome explainer on coordinators! Thanks Paul
@twostraws
@twostraws 5 років тому
Thank you!
@gabrielsscavalcante
@gabrielsscavalcante 5 років тому
Thank you for this video! You just made it clear to me! Congrats!
@twostraws
@twostraws 5 років тому
I'm glad to hear it! Hopefully I'll add a follow-up video soon.
@Erik123211
@Erik123211 3 роки тому
Single storyboard file causes a lot of trouble when working in team. I would also create separate storyboard file for each view controller with the same name. It will help you with merge requests with less conflicts. Anyway, nice and clear tutorial 👌
@keshavkumar1522
@keshavkumar1522 2 роки тому
Thank You So Much, Paul. 🤝👏👏👌 It's pretty clear and precise. Finally I Understood this pattern.
@reece5863
@reece5863 Рік тому
Great tutorial. Thanks for everything! Subscribed.
@jeraldo4571
@jeraldo4571 3 роки тому
Such a good explanation. How about navigating back or popping view controllers and handling view controllers that are not pushed but presented?
@adincebic2992
@adincebic2992 5 років тому
I like that you are narrating most of the things you do in the video.
@twostraws
@twostraws 5 років тому
Yes, that's certainly my intent.
@ikajava
@ikajava 5 років тому
@Pual Hudson Such a perfect guide as always! But, how DRY is a code? You need to write all the methods inside MainCoordinator and repeat the same code in every method. Is there a way to avoid it?
@jackdanyal4329
@jackdanyal4329 4 роки тому
Great tutorial!
@milosmokic5536
@milosmokic5536 5 років тому
Thank you a lot for this. It was a pleasure to watch.
@twostraws
@twostraws 5 років тому
I'm glad you enjoyed it! 👍
@5fcgdaeb
@5fcgdaeb 3 роки тому
Nice and clear explanation! I am guessing the view controllers should hold a reference to the Coordinator protocol but not the concrete MainCoordinator class?
@002sanjay
@002sanjay 4 роки тому
Amazing Clarity of Concept. Thanks Paul. 1 question here, navController in MainCoordinator is visible to all viewcontrollers ?
@melloguitar
@melloguitar 5 років тому
Great class about Coordinators! Thanks!
@twostraws
@twostraws 5 років тому
I'm glad you enjoyed it - make sure you watch the advanced coordinators video, which goes over lots of extras!
@kpapagno
@kpapagno 4 роки тому
I'm just starting out with iOS programming, and of course my first try is with XCode 11. Following video/text gives no compile runtime errors, but when you tap on on of the buttons, it enters the IBfunction but never executes the controller method. After some searching, it appears that you need to do something a bit different now. Instead of making code changes in AppDelegate, I had to put it in SceneDelegate on the scene function. my SceneDelagte now looks like this, and it is working! Thanks for a great tutorial and explanation! import UIKit class SceneDelegate: UIResponder, UIWindowSceneDelegate { var coordinator: MainCoordinator! var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } let appWindow = UIWindow(frame: windowScene.coordinateSpace.bounds) appWindow.windowScene = windowScene let navController = UINavigationController() coordinator = MainCoordinator(navigationController: navController) coordinator.start() appWindow.rootViewController = navController appWindow.makeKeyAndVisible() window = appWindow } . . .
@vinothvino1275
@vinothvino1275 4 роки тому
Thanks man! It's working now.
@user-pi9rd2zr7v
@user-pi9rd2zr7v 4 роки тому
Thanks
@GuruprasadM
@GuruprasadM 4 роки тому
Thank you! This was very helpful.. Paul Hudson, you could consider adding the above in your website so that people with Xcode 11 can follow your tutorial better!
@jhinoventura
@jhinoventura 3 роки тому
Man thx so much. I'm also just starting out and it didin't work following the tutorial. Your changes helped me now it's working. God bless you
@waxelite147
@waxelite147 2 роки тому
Thank you so much, the way Paul wrote it in the "Sundays" ebook did not work even if he updated the code for the SceneDelegate, your way is working perfect. Hope Paul will update the book including your code
@antonsleptsov3185
@antonsleptsov3185 4 роки тому
Nice explanation of the concept. I have one comment regarding components coupling. Yes, applying coordinator you decouple one VC from the other, but you introduce VC+Coordinator coupling instead. As one of possible solution to resolve it we may use blocks like onButtonPressed: () -> Void , which we can inject into VC and do implementation of the block right inside of coordinator. What do you think? Found the answer in the end of next video...
@chrispy104k
@chrispy104k 5 років тому
This is awesome. So much to digest. Would be nice to be able to get the source code.
@NikaKirkitadze
@NikaKirkitadze 3 роки тому
Great video, what about coordinators with multiple Storyboard?
@sebastianstokkebro6481
@sebastianstokkebro6481 5 років тому
Would it be possible to use this practice on programmatically created views/viewcontrollers? Say a dynamic pop-up view.. how does the coordinater handle constraints on dynamic views? how and where should the constraints be handled? Great video btw :-)
@MrDeep0
@MrDeep0 Рік тому
Thank you for that!
@ThomasDaleWood
@ThomasDaleWood 5 років тому
Great video Paul! It would be great to have a video on how to implement/when to use Child Coordinators. Right now when I do Coordinators I only have one. An example showing how to make a destroy children, and also showing how to use Coordinators to create different views on iPhone vs iPad would be super helpful!
@twostraws
@twostraws 5 років тому
I'm working on it!
@multitudes389
@multitudes389 2 роки тому
awesome! It took me a while to get here but finally I got it.
@MohammedJoKu
@MohammedJoKu 3 роки тому
What a brilliant video and I followed the videos instructions there was only one thing that doesn't work when I initialize each ViewController's Coordinator as a weak var functions of the coordinator doesn't get called and when I just remove the weak keyword from coordinator's initialization everything works great idk why and how and this happens in Xcode 11.5
@alonnasi7104
@alonnasi7104 11 місяців тому
Hi Paul! thank you so much for all the hard working you and your team are doing for us all those years! I'm an iOS developer and came across you tutorial here, and just wanted to NOTE something: When using Xcode 14.2, I managed to get this pattern design to work ONLY when implementing the code at 12:00min ('AppDelegate'->'DidFinishLaunching') at ('SceneDelegate'->'WillConnectTo' method) Here's my version of it: guard let windowScene = (scene as? UIWindowScene) else { return } let navigationController = UINavigationController() mainCoordinator = MainCoordinator(navigationController: navigationController) mainCoordinator?.configRootVC() window = UIWindow(windowScene: windowScene) window?.rootViewController = navigationController window?.makeKeyAndVisible() So, to anyone having trouble implementing this tutorial at 2023 - ENJOY! Thx again 😎
@chtozaaliya
@chtozaaliya 11 місяців тому
thank you so much it really helped!
@ritu-pnwhiker8419
@ritu-pnwhiker8419 4 роки тому
Could you please suggest me, how to build custom navigation bar with left and right bar items/buttons using coordinators? For eg. Once user does login and navigates to home screen, that is logout button as right navigation bar item. This will display in all the screens after login screen. How to handle such thing? That all logic goes somewhere in coordinator?
@five-am
@five-am 4 роки тому
Simple, Great.
@joshadams8761
@joshadams8761 5 років тому
Helpful video. Thanks for making it. If you ever tire of Swift, you could work as an animator at Pixar. In that case, please make a WALL-E prequel. I would like to see how the apocalypse happened and how WALL-E experienced it.
@abhishekkumarthakur2116
@abhishekkumarthakur2116 3 роки тому
Awesome video. But how to handle a custom transition presentation of a view controller.
@nebojsapavlovic2231
@nebojsapavlovic2231 5 років тому
You are great! Can you show coordinator for those who don't use storyboards?
@hectorsvill
@hectorsvill 4 роки тому
Thank You!
@SudhanshuSrivastavaIndia
@SudhanshuSrivastavaIndia 4 роки тому
wow, this is awesome
@stanymiles
@stanymiles 5 років тому
This is the whole chapter of your Patterns book)) I use this pattern now. Very useful. (btw I have 8 of your books)
@twostraws
@twostraws 5 років тому
I don't actually include coordinators in Swift Design Patterns, because it's a bit too much of a UI pattern rather than a general language pattern. I did try, but I just don't think it fitted well. Thank you for your support!
@stanymiles
@stanymiles 5 років тому
@@twostraws I checked right now, and you're true. It might be some video then. But I'm pretty sure that I learned this pattern from your material. The code snippet I have is exactly the same. (So much stuff to learn, so I don't even remember where I've learned it from)))
@twostraws
@twostraws 5 років тому
@@stanymiles This is the video version of an article I wrote, which probably explains it: www.hackingwithswift.com/articles/71/how-to-use-the-coordinator-pattern-in-ios-apps
@deepesh259nitk
@deepesh259nitk 2 місяці тому
Dear Paul. Can you recommend any links on how would the co-ordinator pattern be applicable to Swift UI?
@charlesphelps9804
@charlesphelps9804 4 роки тому
If you are using Xcode 11 or newer and want to use the new SceneDelegate, you need to move the AppDelegate code to the SceneDelegate.scene method. After the guard clause, you create the navController, the coordinator, and set the rootViewController. I don't think you need the code to initialize the window because that's taken care of. guard let _ = (scene as? UIWindowScene) else { return } let navController = UINavigationController() // Don't forget to add var coordinator: MainCoordinator? to the top of the class coordinator = MainCoordinator(navigationController: navController) coordinator?.start() window?.rootViewController = navController window?.makeKeyAndVisible()
@tetracosanoic
@tetracosanoic 3 роки тому
thank you so much, couldn't figure out what was wrong with my code
@vladpodvoiskyi2307
@vladpodvoiskyi2307 Рік тому
@@tetracosanoic the same situation
@johnsnow1749
@johnsnow1749 4 роки тому
Where can I download the tutorial project?
@user-dl7uw3dy9c
@user-dl7uw3dy9c 2 роки тому
great! big thx
@daisoreanulaurentiu3943
@daisoreanulaurentiu3943 3 роки тому
Would be nice to see a parallel with SiftUI
@sashamakedonskii
@sashamakedonskii 5 років тому
Thanks for sharing. Do you use Viper pattern ? It will be great to see implementation of app with Viper.
@twostraws
@twostraws 5 років тому
I'm glad it was useful! No, I don't use Viper much - MVC and MVVM mostly.
@jaydice1
@jaydice1 4 роки тому
You should put each storyboard in their own file so that other users on git can work on other classes while you work on your classes.
@rebeloper
@rebeloper 5 років тому
Amazing!
@twostraws
@twostraws 5 років тому
Thank you!
@ayon3527
@ayon3527 5 років тому
looks good Mr. Hudson
@twostraws
@twostraws 5 років тому
I'm glad it's useful!
@atrcl95
@atrcl95 5 років тому
can you show more examples on where the child coordinators can be used, also an app where we have multiple coordinators?
@mikapps9349
@mikapps9349 5 років тому
Agree 100% ...
@twostraws
@twostraws 5 років тому
I'm on the case!
@mikapps9349
@mikapps9349 5 років тому
Christmas is coming early! Thanks Paul.. Could you please consider covering - dealing with default back button (ie replacing with custom), avoiding duplicate child coord entries (its an array so is possible - I had an app the if you pressed 2 buttons at once it would as 2 flow A and flow B... rare case but I did have to prevent this from happening. Wonder if childCoord could be a set? Looking forward to this release!!
@rafaelrincon3109
@rafaelrincon3109 4 роки тому
Looks like he did just that: ukposts.info/have/v-deo/rZVzrZhnhHh-smg.html
@GuruprasadM
@GuruprasadM 4 роки тому
​@@twostraws Great tutorial overall, but it doesn't work entirely for Xcode 11.. Ken Papagno has commented below as to what changes are needed.. could you update those in your website under a new section called Xcode 11 maybe so that they don't face issues?
@loverock5577
@loverock5577 5 років тому
I love this video. Thanks a lot. But can you show how to use coordinators with multiple storyboard?
@smongo1234
@smongo1234 5 років тому
I can recommend coordinators. Really nice video explaining it Paul, as always. I am wondering though, why would the Coordinator protocol describe having a UINavigationController? It should be up to the specific coordinators wether or not it presents things in a navigationcobtroller or something else like a tabbarcontroller or even something custom. The viewcontrollers also don’t need to know that, but with the protocol, they do. Am I missing something?
@twostraws
@twostraws 5 років тому
Yes, I think that's a fair comment - it's usually a better idea to expose as little as possible.
@user-xv2bb6ev7b
@user-xv2bb6ev7b 4 роки тому
looks like I'm missing the childCoordinators variable being initialized. the project build fails since the initialization of the MainCoordinator is not full.
@khongduocbocuoc
@khongduocbocuoc 5 років тому
What if I want to present another NavigationController instead of push
@ahopdanzer
@ahopdanzer 3 роки тому
nice video to explain mvvmc
@fordee1964
@fordee1964 5 років тому
I still think navigation is pretty easy the normal way. The main problem for me is deciding on a navigation stack or going modal. I think with a project greater than around 15,000 lines of code, I would look at a coordinator pattern. In other words if it's a simple app, I would go with the normal way of doing things.
@user-il5ur7kj3i
@user-il5ur7kj3i 4 роки тому
Thanks for information. I just do not understand one thing, if we are using coordinators to break coupling than why do we couple each viewcontroller to exactly one coordinator? Does not this coupling breaks whole idea of coordinators, and making viewcontroller not reusable?
@PedroNeto-nk3td
@PedroNeto-nk3td 2 роки тому
not really, if u have some view controllers like A -> B -> C -> D, but now if u need to add a "X" view between B and C, you would need to go on both to change the flow to A -> B -> X -> C -> D (very simple example) which on a large app might cause problems you won't see at first But if you're using coordinators u just have A,B,C,D,X... and change what points to what in the coordinator.... remember in the example the view controller func buyTapped, the "coordinator?.buySubscription" can be anything. And even if you change the flow of the app, you won't need to change this file (ViewController or BuyViewController), only the coordinator, cause the viewController doesn't know what view coordinator?.buySubscription is...
@dev_jeongdaeri
@dev_jeongdaeri 3 роки тому
Super awesome!!! 😭
@Kukukuk12
@Kukukuk12 5 років тому
Is there any advantage in using storyboards for isolated view controllers over Xibs for each one? Great video as always, Paul!
@mikapps9349
@mikapps9349 5 років тому
Code only > SB > Xibs
@twostraws
@twostraws 5 років тому
Storyboards give a few bonus features that you don't get elsewhere, such as being able to design specific table view cells rather than using prototypes.
@Curpop
@Curpop 10 місяців тому
Liking this 3 years after i watched it the first time
@vandanpatel3395
@vandanpatel3395 5 років тому
GOLD!
@twostraws
@twostraws 5 років тому
I'm glad you liked it!
@MuhammadAli-zv5vz
@MuhammadAli-zv5vz 5 років тому
Great video.How to use this coordinator pattern for separate the delegates and datasources
@twostraws
@twostraws 5 років тому
They are different issues. If you watch my Swift on Sundays videos you'll see I talk about pulling out data sources quite a lot.
@MuhammadAli-zv5vz
@MuhammadAli-zv5vz 5 років тому
Paul Hudson oky
@ramachandrapradhan135
@ramachandrapradhan135 3 роки тому
Rama and shyam are playing football.is it simple or compound sentence,? Sr plz explain it
@DigitalHole
@DigitalHole 5 років тому
Awesome.
@twostraws
@twostraws 5 років тому
Thank you!
@xVinoz
@xVinoz 7 місяців тому
Thank god for saving me of using storyboards lol
@mehmetali1945
@mehmetali1945 Рік тому
Where do we use the childcoordinators array
@amber.k
@amber.k 4 роки тому
I have one doubt here: UIViewController object have storyboard property initialized. Will it increase memory if we create new main storyboard instance everytime?
@ruyneto2007
@ruyneto2007 3 роки тому
Where did you saw?
@greglhotellier5612
@greglhotellier5612 4 роки тому
Someone just told me I might be somewhere here... Thanks for the shoutout! And I hope this joke will have a long life! 😁
@condemned77
@condemned77 5 років тому
How can you declare the coordinator in the ViewController as being 'weak'. When I do this, the compiler says'weak' must not be applied to non-class-bound 'Coordinator'; consider adding a protocol conformance that has a class bound. Did I miss something or is it because I'm using Swift 5 now.
@emrahkorkmaz3991
@emrahkorkmaz3991 5 років тому
hey, did you put to class keyword to your protocol. such as CoordinatorProtocol: class {...} ?
@shivangvyas9584
@shivangvyas9584 4 роки тому
hi @paul, i want to know how coordinator works if we want to add subview to current view controller ? subview can be like child view controller or view with date picker...can be anything...
@shivangvyas9584
@shivangvyas9584 4 роки тому
whose responsibility to add subview to parentview , will it be a coordinator's responsibility or that viewcontroller's responsibility ?
@cnstntVAL
@cnstntVAL 4 роки тому
Confused as to why this isn't working for me, i've copied the code bit by bit and whenever i click on the buttons nothing seems to happen. Strange
@souravvashisht9658
@souravvashisht9658 5 років тому
What if we need to use this pattern in multiple storyboard like if I have 2 storyboard how can I use this pattern there ?🤔
@sub040
@sub040 5 років тому
same as you, maybe we should pass storyBoard name as an argument in function
@RobertHolzapfel
@RobertHolzapfel 4 роки тому
I am thinking: If all the 'Coordinator' is actually doing, is navigation. Why wouldn't we not use just an instance of UINavigationController as "Coordinator"? Even more, when every instance of UIViewController needs a 'var coordinator : Coordinator' while the property 'var navigationController' is already implemented by UIKit for free in every VC. The creation of new VC, as well as the navigation stuff would also be "outsourced' to the, well lets say, to the "MainCoordinatorNC" that inherits from UINavigationController. Bad idea?
@TheVirusRko
@TheVirusRko 4 роки тому
Paul do you think it would be a good idea to mark the coordinator in VC's as Coordinator! instead of Coordinator? I mean, anyway without the coordinator the app will have no sense.
@whitecountryoldroad
@whitecountryoldroad Рік тому
Super late response, but notice that coordinator has a weak reference, which is just a pointer to an object that doesn't protect the object from being deallocated by ARC. That means that you cannot know for sure whether the coordinator variable holds a reference to the AppCoordinator when you try to access it in the VC.
@user-kb3lc5in9d
@user-kb3lc5in9d 5 років тому
What is proper way move from Buy view controller to account view controller using coordinators? Buy view controller must be removed from stack?
@mikapps9349
@mikapps9349 5 років тому
You tell the coordinator to pop it from the stack (or remove if using modal) - but you have to create a custom back button as the standard back button pops it for you. There are some gotta's with coordinators that are not discussed in this intro video.
@TheBishopOfBarton
@TheBishopOfBarton 4 роки тому
I am trying to replicate this, but when I run it, I get a build fail "Type ViewController does not conform to protocol "Storyboarded" in ViewController.swift. I thought this was effectively disabled through removing Main. I think I have followed all your steps... can you help? Thank you.
@lukacefarin2221
@lukacefarin2221 4 роки тому
Check that method name in Storyboarded protocol is the same as method name in Storyboarded extension.
@williamsquires3070
@williamsquires3070 5 років тому
I get a compile-time error: “Method ‘instantiate()’ in non-final class ‘ViewController’ must return ‘Self’ to conform to protocol ‘Storyboarded’. I checked, and the static func instantiate() does return Self, namely: return storyboard.instantiateViewController(withIdentifier: id) as! Self Is it because my Xcode only has Swift 4.0? The error points to the line: static func instantiate() -> Self {
@twostraws
@twostraws 5 років тому
I'm not able to debug small snippets of code, I'm afraid. I definitely suggest that you start by updating Xcode to rule out any problems, but once you've done that and compared your code to mine on screen, you're welcome to email me if you still have problems.
@markuspfeifer8473
@markuspfeifer8473 4 роки тому
I came up with a solution inspired by functional programming. My view controllers manage presenting the next view controller on their own, but which view controller they present is decided by a closure. All they know about is what data they can provide to the next view controller and possibly some labels for the data. For example, if you have a view controller that allows you to select three numbers using sliders and submits these numbers with an ok button, that one would take a closure of type (Float, Float, Float) -> UIViewController and some description what those sliders mean etc
@markuspfeifer8473
@markuspfeifer8473 4 роки тому
If you have some chain of views, this essentially amounts to currying. A view controller is just a higher order function.
@markuspfeifer8473
@markuspfeifer8473 4 роки тому
Both solutions are mostly equivalent, but they have pros and cons. Coordinators introduce a clearer separation between logic and view, but they are more verbose and one has to remember assigning the coordinator to each view controller. My solution gives you a clear idea what data a view can provide and consume and you can see entire workflows ahhh a glance, but I actually tend to declare them in root view controllers of storyboards (which do nothing but coordinating those Workflows and maybe hold some references that they pass down). It’s a bit of a technical artifact that coordinators in my solution happen to be view controllers. Also, your solution makes it easy to instantiate the exact same view controller from everywhere by calling some function which is nice and avoids a boilerplate in my solution that I have to tell every view controller that wants x where to find x; on the other hand, that kind of looks like tight coupling through the backdoor as you replace knowing which view controller to instantiate by knowing which coordinator function to call.
@clomasss3359
@clomasss3359 3 роки тому
Is anyone having an issue where the frame size of UIWindow is too small for any device? I've tried two different projects.
@kosta3ov
@kosta3ov 5 років тому
Can view controller delegate prepareForSegue in coordinator?
@twostraws
@twostraws 5 років тому
Can it? Sure - it can just pass on the call. *Should* it? No; I don't recommend using segues.
@oboomabom
@oboomabom 5 років тому
How would you use this with view controllers that need information to know what to display? E.g. a profile would need an ID. Just as parameters to the coordinator functions?
@mikapps9349
@mikapps9349 5 років тому
You inject the data into the VC when you init them within the coordinator.
@oboomabom
@oboomabom 5 років тому
@@mikapps9349 how does the coordinator get it though?
@mikapps9349
@mikapps9349 5 років тому
@@oboomabom when you create the coordinator you give it all the data in needs so it can pass what is required to VCFoo or VCBar etc...
@oboomabom
@oboomabom 5 років тому
@@mikapps9349 I'm a bit confused. If it needs the data when it's created then isn't that, in a way, a soft dependency with the destination view controller? Like how would I use a coordinator to go to the profile of one of my users that I'm displaying in a table view on my current vc?
@mikapps9349
@mikapps9349 5 років тому
Say you have a UsersCoordinator, which controls showing / hiding your views. One view (View Bar) could be a list of all students, another view (View Foo) could be a single profile of one user. Note view bar and foo don't know about each other at all! Flow example, you want to show View Bar.... the coordinator's role is to show this. You may have a UserModelController class (that's injected into the coordinator) which you can ask for allUsers or a singleUser. Coordinator shows View Bar, and provides the VC with all necessary info. You then select a cell to show a users profile. You ask the coordinator - showFooView(withUserID:) and pass in that users ID (for example) then within the coordinator you can ask UserModelController ... get this user with this ID and then inject that into the FooView. All flow is directed through the coordinator. This is how I do it, maybe there are other ways. With protocols etc, but this simple. Hope that helps. Otherwise create a question on stackoverflow.
@TheBardsCorner
@TheBardsCorner 4 роки тому
How should we complete the part at min 12:00 in Xcode 11 since the introduction of the Scene Delegate file? I tried to put the code as yours but it doesn't work. I tried to put that in Scene Delegate but it doesn't work. Thanks
@joemccraw2374
@joemccraw2374 4 роки тому
Take a look at this comment above from Łukasz Gierałtowski "If you are using Xcode 11 or newer: 1) Coordinators project > General > Deployment Info > Target > set 12.1 2) AppDelegate.swift > remove both UISceneSession methods, 3) Info.plist > remove Application Scene Manifest property."
@002sanjay
@002sanjay 4 роки тому
@@joemccraw2374 You can add the below code to your scenedelegate will connect to session class window = UIWindow(frame:windowScene.coordinateSpace.bounds) window?.windowScene = windowScene let navController = UINavigationController() mainCoordinator = MainCoordinator(navController: navController) mainCoordinator?.start() window?.rootViewController = navController window?.makeKeyAndVisible()
@khongduocbocuoc
@khongduocbocuoc 4 роки тому
15:53 is it violating Interface segregation principle ?
@federicodominguezdaniel
@federicodominguezdaniel 3 роки тому
Yes , but on 15:13 he explains why and recomend to use protocols in larger apps. (Sorry for my bad english haha )
@Charlot1914
@Charlot1914 2 роки тому
I don't get it why we need to set vc.coordinator = self. And what's the point of the childCoordinators?
@vadirajhippargi9285
@vadirajhippargi9285 5 років тому
Just wondering what if we also wanted to pass data between VCs. With Coordinator pattern, should coordinator code be made to take care of that too. How do we let VC know the coordinator telling "If you want me to push this to so and so VC, then you are also supposed to supply me with this and this data".
@vadirajhippargi9285
@vadirajhippargi9285 5 років тому
@David van Enckevort Thanks David, So Essentially that code also need to go into Coordinator, right?
@vadirajhippargi9285
@vadirajhippargi9285 5 років тому
@David van Enckevort Thanks, this helps.
@allesmaze8710
@allesmaze8710 4 роки тому
do you have an instagram or other kind of social media page?
@petersuvara
@petersuvara 4 роки тому
MVC and Apples setups are pretty easy to understand and work well. Coordinators can easily become over engineered, and everyone creates an app that uses a different coordinator implementation, which you'll have to learn EVERY TIME! Yes, work in the industry long enough and you'll see that every app has a different Coordinator implementation that's just as different as you could imagine, without the supporting documentation (like you have with apples standards library).
@eminRoblack
@eminRoblack 5 років тому
This is so awesome and i can see the benefits...but for some reason i am still not getting it 100% :/ And I don't want to copy/paste the code and just use it without understanding how it is made from skratch. I guess i will put this video on repeat and try to figure out which pieces i am missing :) Great video!
@twostraws
@twostraws 5 років тому
Feel free to tweet me (@twostraws) if you have specific questions. I hope to make a follow-up video addressing common questions, so please ask!
@eminRoblack
@eminRoblack 5 років тому
@@twostraws Tnx Paul! I will do that if i hit a wall again. You explained it very well so i expect going over the video and getting some reading done will clear things up :)
@eminRoblack
@eminRoblack 5 років тому
@@twostraws HA! I actually did it! It feels so much clearer now. I guess this is what you feel every day....kinda :) I feel i have the power to manipulate the world now! I acutally went over your article and it helped going over code line by line with your added comments there. Awesome stuff!
@JurisAndersons
@JurisAndersons 4 роки тому
Paul, giving all view controllers "weak var coordinator: MainCoordinator?" dependency is not a good thing...
@JurisAndersons
@JurisAndersons 3 роки тому
@@MsUzoAgu several ways. 1) pass a closure instead of coordinator for callback, 2) hide MainController behind a protocol.
@AivarsMeijers
@AivarsMeijers 5 років тому
Great video, subscribed. Curious how wasn’t subscribed yet ¯\_(ツ)_/¯ Already used coordinators for one of small projects after reading your post “How to use the coordinator pattern in iOS apps”. Now I’m thinking about slow migration to MVS+Cordinators for one of the projects with really huge VC classes. Could be interesting to hear opinion and expierience from others about risks and edge cases for slow migration. No way to rewrite everything in one release, there are more than 40 screens in that app.
@twostraws
@twostraws 5 років тому
You probably hadn't subscribed because I don't do that much on UKposts - I'm figuring things out slowly :) You don't need to dive in with coordinators everywhere; try adding it to just part of your app and go from there.
@WilliamGattoFilho
@WilliamGattoFilho Рік тому
Dude you rock, Imma pay ya a coffee in person one day. 5:13 7:39
@user-pl3je1vt8k
@user-pl3je1vt8k 3 роки тому
Start here 3:33
@petersuvara
@petersuvara 4 роки тому
What? Ofcourse you can reuse Segways... and the point is that you want it hard-coded so you have a clear flow. Sounds like coordinators are just another adventure in over-engineering. I've been using Coordinators in this pattern and if you have some interesting design, you'll run into all the same problems as and more when it comes to displaying content. In fact, it becomes more complex because the state of screens becomes lost as you move between views. I would only recommend coordinators for large enterprise applications without novel/unique design.
@kikiwora
@kikiwora 2 місяці тому
Storyboards and XIBs are not needed. We all shall use Code and Previews
@tenminutetokyo2643
@tenminutetokyo2643 4 роки тому
Nice but keep em under 10 mins.
Advanced Coordinators in iOS
18:55
Paul Hudson
Переглядів 40 тис.
Самый большой бутер в столовке! @krus-kos
00:42
Кушать Хочу
Переглядів 6 млн
Завтра в школу с... | Шоу-квиз «Вопросики»
00:28
Телеканал СОЛНЦЕ
Переглядів 1,5 млн
MVVM + Data Driven UI на практике swift
40:22
The Swift Developers
Переглядів 20 тис.
How to Use MVVM (Model View ViewModel) in Swift & iOS - 2023
16:50
iOS Academy
Переглядів 56 тис.
Clean iOS Architecture pt.5: MVC, MVVM, and MVP (UI Design Patterns)
16:09
Essential Developer
Переглядів 112 тис.
Coordinator pattern in iOS Swift Part 1 | Hindi tutorial
19:16
Code Cat
Переглядів 10 тис.
Write Better Code with Swift Algorithms
34:34
Paul Hudson
Переглядів 31 тис.
SwiftUI - Intro to MVVM | Example Refactor | Model View ViewModel
11:55
Я Создал Новый Айфон!
0:59
FLV
Переглядів 646 тис.
Интел подвинься, ARM уже в ПК!
14:06
PRO Hi-Tech
Переглядів 139 тис.
СКОЛЬКО ЕЩЕ БУДЕТ АКТУАЛЕН IPHONE 13?
14:10
DimaViper Live
Переглядів 40 тис.