Swift: Dependency Injection Tutorial (2022) - iOS
HTML-код
- Опубликовано: 11 июл 2024
- In this video we take a practical look at dependency injection in Swift by using protocols. Dependency Injection is a powerful pattern to build scalable large applications with decoupled logic. It allows objects to use common functionality in an agnostic way; such that one object does not know where the functionality comes from. We'll be working in Xcode 12 and Swift 5 to demonstrate this with multiple targets.
💻 Source Code: / iosacademy
🎥 Subscribe for more: ruclips.net/user/iOSAcademy?su...
😎 Like my teaching style? Check out some of my most popular courses! courses.iosacademy.io
** Popular Series
Building Instagram: courses.iosacademy.io/p/build...
Building TikTok: / @iosacademy
SwiftUI for Beginners: ios-academy.teachable.com/p/s...
** Get Skillshare free for 2 Months and learn iOS
www.skillshare.com/r/user/afraz
** Manage all your investments from app earnings on Betterment!
bit.ly/3eBwlI9
** Grow your own RUclips tech channel with TubeBuddy:
www.tubebuddy.com/iosacademy
*Timestamps*
0:00 Swift Dependency Injection
0:49 Create Project
1:50 Create Button
3:24 Create Xcode Target
4:28 Create API Caller
6:17 Create New Target
9:39 Decode API Response
10:40 Create Protocol
13:19 Pass Dependency
18:00 Finalize Data
19:30 Set Up TableView
22:05 Dependency Injection Review
24:14 Wrap Up / Outro
#swift #dependency #iOS
Out of million tutorials about DI, this one explains it crystal clear and in a very simple way to understand. Thank you so much. Keep it up 👍🏻
Youre welcome!
Why did you use singleton despite you used dependency injection? i know that one of dependency injection benefit is to remove singleton!!
same question here
I was waiting so hard for this! Thank you so much
You’re welcome
Fantastic video - clear and concise! Cheers!
Glad it was helpful!
Been waiting for this! Thanks a lot!
Hope you enjoyed it!
@@iOSAcademy hey, Do you have learning path for beginner to advance like this topics(di,reactive programming etc)
Loved it! Thank You so much.
Youre welcome
Smashing that like button even before watching the video. Thank you!
You're the best!
Thanks alot brother 👍 perfect understandable explination 💗 loads of love 💗😍
You’re welcome!!
suuuuper helpful. thanks!
Youre welcome
Thank you for this wonderful tutorial! One question: so the in the dataFetchable protocol, the function needs to have the exact same name with the one inside ApiCaller right ?
DI with MVVM example? Awesome video btw, thanks
Sure! And thanks!
Impressive!!!
thanks
Beautiful
Thanks
Excellent
Thanks!
This is a great tutorial...Thanks a lot! Moarrrr plzzzzz.
Thanks!
please can we have another DI tutorials that talks more in depth concepts and how to work with MVVM
Much appreciated !!!
Pls make a tutorial about distribute app over the air
Thanks
You're welcome! 😎
How do you inject to the home view controller when it's embedded in a Navigation Controller?
brilliant di tutorial
Thanks
It was great video but I have different question. What should we do when we require a data to multiple places? I was thinking dependency injection is related to this but it seems it doesnt so I am little confused.
Hi, Thanks for great lesson with easy practical sample. I have one doubt, This injecting will works only on Targets or it will work classes too?
Youre welcome. Yep it works for both
@@iOSAcademy Thank you 🙂🙂
Can you possibly explain the @escaping closures and callback and the reason for this instead of making the function return something? New to iOS development
Hi Cesar, using callback function to return a value is a common approach to achieve asynchronous function in programming. In this case, the function have to be asynchronous as the network API call is not returning the value immediately. @escaping closure is just the Swift way of implementing callback.
@@novo4249 thank you so much Hans! I appreciate it!
I have multiple environments how can I manage them?
This was a very nice tutorial. I know it's slightly off topic but how would you handle dependencies of your separated out targets. Let's say you network module depends on alamofire but you do not want you main app to depend on alamofire.
I mean correct me if I'm wrong but once you import 3rd party dependencies to assist with backend network calls wouldn't it now become a global asset to the whole project? Anything having to do with the API would require you importing in alamofire for each file no?
@@ApoCaLypSeXVII I think we can also setup 3rd party for individual targets.
I broke my iPhone smashing the like button 😩
Oh no!
I smashed like button with broken phone
Great Video! Isn't that dependency inversion?
Exactly my thoughts!
Brother for learning iOS development do we need Mac laptop or any other alternatives and if we want to buy apple laptop what OS needs to be purchased bro
Yes you need a mac with macos
@@iOSAcademy what OS Catalina or bigsur
@@iOSAcademy can we do swift programming in virtual machines
Should 256gb be enough for balancing college work and xcode projects or should i invest in 512gb storage? I am going to be purchasing a macbook air soon and don’t know how much storage xcode takes up. Thanks
255gb is definitely to small. U need at least 512gb.
Id invest in 512
16 gb of ram, minimum
@@johncerpa3782 ordered 512gb ssd 16gb ram
kit
I’ve only been doing iOS development a few weeks, glad to see I’m not alone with Xcode being really flaky. Visual Studio isn’t perfect, but it seems way more stable and consistent.
import UsefullKit
Thanks!
Enjoy my teaching style? Check out iOS Academy+ at iosacademy.io/plus
this was way too fast
👍👍👍
Thanks