Why You Should Use The SwiftUI Coordinator Pattern

  Рет қаралды 15,386

Rebeloper - Rebel Developer

Rebeloper - Rebel Developer

Күн бұрын

Пікірлер: 77
@rebeloper
@rebeloper Жыл бұрын
Firebase Firestore in SwiftUI Demystified 👉 kzbin.infozSuEvcXbBTw?feature=share
@davidcbeaudoin
@davidcbeaudoin Жыл бұрын
I'm very much a SwiftUI beginner, so I'm still working on wrapping my head around much of the basics. This is a great, easy to understand approach to navigation. Thank you for the great tutorial!
@rebeloper
@rebeloper Жыл бұрын
Glad it was helpful! If you want to boost your learning check out SwiftUI Camp: store.rebeloper.com/swiftui-camp-habit-tracker-edition?coupon=KZbin
@YourLaw
@YourLaw Жыл бұрын
I have watched a lot of your videos, this is your best video. Clean crisp explanation of a topic.
@rebeloper
@rebeloper Жыл бұрын
Glad you liked it. Next learn about @Observable @Bindable in iOS17 - SwiftUI Data Flow 👇 kzbin.info/www/bejne/f5jFnZptmJeHZ9E&ab_channel=Rebeloper-RebelDeveloper
@Xcoder-Ayush
@Xcoder-Ayush 2 ай бұрын
Great tutorial! I have enhanced this to pass data from one View to another in this coordinator pattern in SwiftUI. 😀
@rebeloper
@rebeloper 2 ай бұрын
That's great! Have you seen my latest video? 👉 NavigationStack vs. NavigationCoordinator: You Won’t Believe the Difference! kzbin.info/www/bejne/bZfFaHaOqd5on5Y
@stevenkirke
@stevenkirke 7 ай бұрын
Much appreciated for the very explanatory tutorial!
@rebeloper
@rebeloper 7 ай бұрын
You're very welcome! Next watch: SwiftUI Text - EVERYTHING You Need to Know 👇 kzbin.info/www/bejne/qHyol6Zrn5h0hKc&ab_channel=Rebeloper-RebelDeveloper
@glnygl8525
@glnygl8525 2 ай бұрын
Hi Steven, I faced same problem as yours. Fetching data several times when I go to detail and come back. I tried to fix this using a propery like did load which is worked but Im still curious about how did you solve this and looking for a better way
@cagrgider8320
@cagrgider8320 Жыл бұрын
That looks clean, thanks a lot. But how can we pass a value to the following view with this pattern?
@rebeloper
@rebeloper Жыл бұрын
Good question! For that you might want to check out NavigationRouter: store.rebeloper.com/navigation-router Or SwiftUI Camp (50% OFF discount in the link): store.rebeloper.com/swiftui-camp-twitter-edition?coupon=KZbin Expires January the 31st
@DragunXtreme
@DragunXtreme Жыл бұрын
How I can set parameters in a View using this pattern? I like very much how you control the navigation is simple and direct, but the views that you use in this example don't receive any argument and I don't no how adapter your Enum Page to receive some parameters depends of View called. But congratulations for the video, your explanation is wonderful
@rebeloper
@rebeloper Жыл бұрын
You can add a dependency on the enum value. I can show you how on a mentoring session here: rebeloper.com/mentoring Next check out SwiftUI Navigation Perfected: Harnessing NStack's Game-changing Capabilities 👇 kzbin.info/www/bejne/pKPXo2RqnrSdZqc&ab_channel=Rebeloper-RebelDeveloper
@bas3485
@bas3485 Жыл бұрын
Nice video! I like the idea. Do you also have videos about navigation for lower deployment targets? I could use some inspiration
@rebeloper
@rebeloper Жыл бұрын
Yes I do! Check out my store: store.rebeloper.com Let me show you a Progress Button in SwiftUI 👇 kzbin.info/www/bejne/oXebgp5obZJ5fLc
@russel_dev
@russel_dev 6 ай бұрын
Nice video. But some tips, in Coordinator View & ViewModel should also be coupled tightly.
@rebeloper
@rebeloper 6 ай бұрын
Thanks for the tip. What do you think about this one: kzbin.info/www/bejne/qZrOc3Rvo5p7aM0
@marksiracusano9931
@marksiracusano9931 3 ай бұрын
Thank you very much for the video. How would you handle a situation with child coordinators though? Would you create CoordinatorViews for each and instantiate the coordinators there too?
@rebeloper
@rebeloper 2 ай бұрын
I avid child coordinators like the plague :) Have you seen my latest video? 👉 NavigationStack vs. NavigationCoordinator: You Won’t Believe the Difference! kzbin.info/www/bejne/bZfFaHaOqd5on5Y
@sami790311
@sami790311 Жыл бұрын
I like the example. However, there is one thing that still creates a strong coupling between views. Despite the fact that the coordinator is taking care of the navigation, the views are still knowing about other views. What if from BananaView I want to present different views depending on the case? The views should be agnostic about other views. This way they can be reused. I think adding to the coordinator pattern the composition pattern could solve the problem.
@rebeloper
@rebeloper Жыл бұрын
Thank you for the feedback. What do you think of the next video: Dependency Injection in SwiftUI, the Best Pattern: kzbin.info/www/bejne/gpXVl2tnrplkptk&ab_channel=Rebeloper-RebelDeveloper
@alexthurston9940
@alexthurston9940 Жыл бұрын
This is a problem with SwiftUI since we need to type the view hierarchy for performance reasons. I’m not sure of any way around it beside AnyView which is bad for performance. Maybe someday! Otherwise you can use UIKit for navigation under the hood.
@Spacer-l3j
@Spacer-l3j 7 ай бұрын
@@alexthurston9940 Why do you think AnyView is bad for perfomance? AnyView is fine for a small project
@BabuLal-bf6oq
@BabuLal-bf6oq Жыл бұрын
It's really nice explanation but can you please let me know how to pass data to another view using this coordinator pattern.
@rebeloper
@rebeloper Жыл бұрын
Check out NavigationRouter from kindaSwiftUI: github.com/rebeloperAlpar/kindaSwiftUI/wiki/NavigationRouter Next Unlock the Power of Core Data Versioning! 👇 kzbin.info/www/bejne/iHXXfYqNpNhmmaM&ab_channel=Rebeloper-RebelDeveloper
@arekugureman
@arekugureman 14 күн бұрын
This is very simple, and a good tutorial, however for more complex scenarios, won't you need to a coordinator per app flow? As it is, your Coordinator will require to know all possible screens, making it not so scalable :/
@rebeloper
@rebeloper 12 күн бұрын
Yes, that is one approach to more complex apps. Next check out AI in Xcode: Elevate Your App Development to the Next Level 👇 kzbin.info/www/bejne/gmiyepKlZq6BaaM&ab_channel=Rebeloper-RebelDeveloper
@AdelUI
@AdelUI Жыл бұрын
First of all, thanx for amazing contents , however, what's the different between coordinator pattern & Routes ?
@rebeloper
@rebeloper Жыл бұрын
In my view no difference between them. It's just Coordinator sound more techy :P BTW have you seen Firebase Login in SwiftUI: Step by Step Masterclass 👇 kzbin.info/www/bejne/b521iJSrapaffdk&ab_channel=Rebeloper-RebelDeveloper
@russellwarwick
@russellwarwick 9 ай бұрын
Nice example! However the view still knows about its navigation path. Coordinator should also address tight coupling of view and navigation. Any thoughts on this?
@rebeloper
@rebeloper 9 ай бұрын
I have a solution for that (it's paid): kzbin.info/www/bejne/pKPXo2RqnrSdZqcsi=xUPBOBdeVox-C7FO Next Discover the 5 Best View Extensions in SwiftUI 👇 kzbin.info/www/bejne/pGqknp-iaNGMb6s&ab_channel=Rebeloper-RebelDeveloper
@russellwarwick
@russellwarwick 9 ай бұрын
Nice concept with NStack however it doesn’t really solve the problem of the View knowing about its navigation path. The View should be dumb so it can be reused elsewhere without attaching all of that navigation logic. The view should only know that a button was pressed or an action was performed. It’s then the responsibility of a Coordinator to dictate the next step, not the view. I’m not sure if it’s a limitation with SwiftUI though.
@rebeloper
@rebeloper 9 ай бұрын
Good points. I might add this into NStack at some point in the future. Next find out the Top 24 Xcode Shortcuts For Beginners 👇 kzbin.info/www/bejne/bIXYfKKqgsmrfrM&ab_channel=Rebeloper-RebelDeveloper
@AppDeveloperPoint
@AppDeveloperPoint Жыл бұрын
Thanks for this video. I have one question here, How you will manage the switch case fro large complex app when you need to route to say 50 screens. ?
@rebeloper
@rebeloper Жыл бұрын
This can be used for 5 or 50 screens too. Number of screens does not matter. Let me show you a Progress Button in SwiftUI 👇 kzbin.info/www/bejne/oXebgp5obZJ5fLc
@AppDeveloperPoint
@AppDeveloperPoint Жыл бұрын
@@rebeloper yes we can write 100 cases. But will that be a good practice?
@rebeloper
@rebeloper Жыл бұрын
I don't see why it could be a bad practice. BTW check out my lates video 👉 2023's Must-Have Xcode Extensions: Revealed Here! 👇 kzbin.info/www/bejne/amKXaoWraa1nmKs
@star_maze
@star_maze Жыл бұрын
@@AppDeveloperPoint in that case you need to consider the modular approach to your architecture where each module will have its coordinator. The global coordinator will handle routes between the modules.
@HINDISE_ENGLISHTAK
@HINDISE_ENGLISHTAK Жыл бұрын
Nice Explanation! how about popTo any particular view like popToThirdView, popToSecondView etc ?
@rebeloper
@rebeloper Жыл бұрын
You can do all of those with NavigationRouter found in my community: store.rebeloper.com/community If you're a SwiftUI developer you will love: Unveiling The 10 Commandments of SwiftUI - #4 Will Surprise You! 👇 kzbin.info/www/bejne/aZ-rfGiZqbF2hKc
@nartiscoding
@nartiscoding 3 ай бұрын
Will this code work for the cases when I need to open a sheet inside a sheet, a fullscreen cover inside a sheet, a sheet inside a fullscreen cover, and so on?
@rebeloper
@rebeloper 2 ай бұрын
Not at this stage of the code, but Navigation Coordinator does: kzbin.info/www/bejne/bZfFaHaOqd5on5Y
@JamieGray-w6q
@JamieGray-w6q Жыл бұрын
Any chance you've found a fix the white flash this navigation system now produces in iOS17? Prior releases of iOS worked perfectly, but now there's an annoying white flash on any pop(). Been messing around with several alternatives to update the background color, but have been unsuccessful so far.
@rebeloper
@rebeloper Жыл бұрын
Must wait for an iOS update for this fix :( Next watch -> From Boring to Breathtaking: Mastering SwiftUI Splash Screens for Remarkable App Launches 👇 kzbin.info/www/bejne/onOmoaqPedGdras&ab_channel=Rebeloper-RebelDeveloper
@NeerajGurjar-dx1rr
@NeerajGurjar-dx1rr Жыл бұрын
It is very helpful but what if we need to send data from one view to another view how can we do this. can you help
@rebeloper
@rebeloper Жыл бұрын
Here you go: Dependency Injection in SwiftUI, the Best Pattern: kzbin.info/www/bejne/gpXVl2tnrplkptk&ab_channel=Rebeloper-RebelDeveloper
@glnygl8525
@glnygl8525 2 ай бұрын
Thank you for video. But here is an issue if you want to fetch data in .task or onAppear views are recreating several times so app is trying to fetch data again again again. We can handle this problem with a state property like isLoaded or something but do we need this really or do you have a better idea to solve this problem?
@rebeloper
@rebeloper 2 ай бұрын
That is a great solution. I actually have a view modifier for my client projects to solve this issue. Have you seen my latest video? 👉 NavigationStack vs. NavigationCoordinator: You Won’t Believe the Difference! kzbin.info/www/bejne/bZfFaHaOqd5on5Y
@glnygl8525
@glnygl8525 2 ай бұрын
@@rebeloper thank you for answer I also coded a view modifier like viewDidLoad
@glnygl8525
@glnygl8525 2 ай бұрын
@@rebeloper here is another question if we have a binding value in a view that we build in coordinator. How we can pass data to this view in coordinator. I can send state data like "case (let value) " but this is not binding value
@glnygl8525
@glnygl8525 2 ай бұрын
case .detail(let isSelected): DetailView(isSelected: $isSelected) isSelected binding value and error message is cannot convert 'Bool' to expected argument type 'Binding'
@TheClampet23
@TheClampet23 Жыл бұрын
trying to present a sheet from another sheet with this method, but the app dismisses the first sheet before presenting the new one. how would you solve for that?
@rebeloper
@rebeloper Жыл бұрын
A sheets should be presented upon the change of a Published variable. Use different ones for more sheets. If you need more help consider booking a mentoring session: rebeloper.com/mentoring Next Learn About One Fatal Programming Mistake: Stop Making it a Hobby! 👇 kzbin.info/www/bejne/gobWqpV8fahnedE&ab_channel=Rebeloper-RebelDeveloper
@d_e_e_p_a_k_000
@d_e_e_p_a_k_000 Жыл бұрын
Apple should provide such classes in early version of iOS atleast 14.0 but it's available on iOS 16.0. Most of product base iOS versions supports 13.0.
@rebeloper
@rebeloper Жыл бұрын
Totally agree. Did you wonder if will AI replace programmers? Check out my take on it 👇 kzbin.info/www/bejne/b3_PdnZ4fK5gha8&ab_channel=Rebeloper-RebelDeveloper
@sergioudalov361
@sergioudalov361 Жыл бұрын
looks nice, but what if we got 100 screens?) it will be very huge enum...)
@rebeloper
@rebeloper Жыл бұрын
Still clearer than having those 100 screens scattered all of=ver the project, right? Let me show you a Progress Button in SwiftUI 👇 kzbin.info/www/bejne/oXebgp5obZJ5fLc
@hosseindastan6221
@hosseindastan6221 Жыл бұрын
what about passing ID for specific view?
@rebeloper
@rebeloper Жыл бұрын
Why would you do that? Let me show you a Progress Button in SwiftUI 👇 kzbin.info/www/bejne/oXebgp5obZJ5fLc
@iansmith9368
@iansmith9368 Жыл бұрын
I have tried this pattern using NavigationLinks instead of buttons, but the environment doesn't get passed 'down'. Perhaps NavigationLink doesn't create a child.
@rebeloper
@rebeloper Жыл бұрын
Maybe you're not using the latest SwiftUI. Check out a solution for all SwiftUI versions here: kzbin.info/www/bejne/pKPXo2RqnrSdZqc&ab_channel=Rebeloper-RebelDeveloper BTW have you seen Firebase Login in SwiftUI: Step by Step Masterclass 👇 kzbin.info/www/bejne/b521iJSrapaffdk&ab_channel=Rebeloper-RebelDeveloper
@discodolken
@discodolken Жыл бұрын
This wouldn't work, if you want to present a sheet from a detail view. Then the coordinator will present that sheet from the initial view, leading to a warning in the console
@rebeloper
@rebeloper Жыл бұрын
Thanks for letting me know. Since than I have perfected a library for SwiftUI Navigation: store.rebeloper.com/nstack BTW watch me take my own SwiftUI test here 👇 kzbin.info/www/bejne/b4G7g2ifjb1gbc0&ab_channel=Rebeloper-RebelDeveloper
@TharinduRameshKetipearachchi
@TharinduRameshKetipearachchi Жыл бұрын
I think this isn't thread safe @Published var path = NavigationPath() Xcode giving me the following error Publishing changes from within view updates is not allowed, this will cause undefined behavior.
@rebeloper
@rebeloper Жыл бұрын
Put @MainActor on your class :) Here's Why You Shouldn't Nest Your Code 👇 kzbin.info/www/bejne/e5TIgpmOZ8pjo7c&ab_channel=Rebeloper-RebelDeveloper
@TharinduRameshKetipearachchi
@TharinduRameshKetipearachchi Жыл бұрын
@@rebeloper Thanks ☺
@TharinduRameshKetipearachchi
@TharinduRameshKetipearachchi Жыл бұрын
@@rebeloper Still I'm getting that warning Publishing changes from within view updates is not allowed, this will cause undefined behavior. This is coming for following line @Published var path = NavigationPath()
@rebeloper
@rebeloper Жыл бұрын
I can take a look at your code on a mentoring session and debug it: rebeloper.com/mentoring Next check out WWDC23: You're NOT Ready for this WWDC23 Wish List! 👇 kzbin.info/www/bejne/o6TNnGl5f9WWj5o&ab_channel=Rebeloper-RebelDeveloper
@StianF
@StianF 7 ай бұрын
What about actual use cases where data needs to be passed back and forth, or where a single view can be presented as both page and sheet and cover? We gotta pay $2000 dollars to learn? Bullshit moneyscam
@rebeloper
@rebeloper 7 ай бұрын
Use an EnvironmentObject to access data from any of the views. Next escape the GeometryReader nightmare 👇 kzbin.info/www/bejne/sJeQgqGuadGUipY&ab_channel=Rebeloper-RebelDeveloper
@AryamanSharda
@AryamanSharda 6 ай бұрын
If this screen is reused elsewhere in the app, in a different user flow for example, then specifying the Coordinator in the View makes it so coupled that I wouldn't be able to reuse this view anymore right? I wouldn't be able to use it with both CoordinatorA and CoordinatorB. The equivalent `Page` enum for CoordinatorA and CoordinatorB may have entirely different cases so specifying a single Coordinator and making calls like `coordinator.push(.banana)` make it so I can't reuse this view in any other flow in my app.
@rebeloper
@rebeloper 5 ай бұрын
Check out this new version and let me know what you think: store.rebeloper.com/navigation-coordinator Next check out my latest video about Mastering SwiftUI Error Alerts: Fix Your App in Seconds! 👇 kzbin.info/www/bejne/nZ3KYp6lgrisgqM&ab_channel=Rebeloper-RebelDeveloper
"كان عليّ أكل بقايا الطعام قبل هذا اليوم 🥹"
00:40
Holly Wolly Bow Arabic
Рет қаралды 10 МЛН
My Daughter's Dumplings Are Filled With Coins #funny #cute #comedy
00:18
Funny daughter's daily life
Рет қаралды 33 МЛН
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,5 МЛН
Dependency Injection in SwiftUI, the Best Pattern
14:55
Rebeloper - Rebel Developer
Рет қаралды 4,3 М.
SwiftUI's Mini Coordinator Pattern Demystified
23:21
Rebeloper - Rebel Developer
Рет қаралды 1,8 М.
Programmatic Navigation in SwiftUI explained
17:50
donny wals
Рет қаралды 5 М.
How to use NavigationStack in SwiftUI | Bootcamp #62
23:59
Swiftful Thinking
Рет қаралды 36 М.
SwiftUI Coordinator Pattern: Everything You Need to Know
37:21
Rebeloper - Rebel Developer
Рет қаралды 2,1 М.
How to use @Observable Macro in SwiftUI | Bootcamp #76
18:52
Swiftful Thinking
Рет қаралды 7 М.
"كان عليّ أكل بقايا الطعام قبل هذا اليوم 🥹"
00:40
Holly Wolly Bow Arabic
Рет қаралды 10 МЛН