Dependency Injection | Swift 4, Xcode 9

preview_player
Показать описание
Today we talk about another design pattern called dependency injection. Dependency injection is the preferred design pattern for accessing you helper/manager/service classes without using singletons. We are going to be covering how to use DI with both storyboards and programmatically.

*** Show Notes and Links ***

Project Files:

Kyle Lee on Social Media:

Hone My Hustle on Social Media:

---------GEAR -------

Camera - Logitech C920 Webcam

Tripod - Manfrotto Compact Tripod

Laptop - 2017 MacBook Pro

Microphone - PowerDeWise Lavalier Microphone

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, we’ll receive a small commission. This helps support the channel and allows us to continue to make videos like this. Thank you for the support!

About This Video:
In this video, Kilo Loco gives an example of how a developer would use dependency injection (DI) for both storyboards and programmatically. He also goes over the different types of dependency injections a developer can use in their project. Check it out!
Рекомендации по теме
Комментарии
Автор

Good intro to the topic. One thing that you’ll find if you work on big projects is that you’re going to have lots of dependencies so you end up creating these bloated initializers that look horrific and suck to use. That’s where protocols come in to take all your dependencies, wrap them up in a nice neat package to be used later on. Testable and swifty!! I think a lot of people could benefit from demonstrating this protocol oriented approach to dependency injection. Keep it up!

mattsanford
Автор

Thank you so much for this video! I've always been scared of dependency injections because it sounded so complicated. Even articles online do a very poor job of explaining it. But watching this video, I'm baffled by how easy this was!

Piglet
Автор

Great job (your video's always are). However I'm still at a loss as to "why use DI"? it seems like the original code with the singleton was much smaller a straight forward. I get asked about DI all the time, and I'm still not sure of "why do we use it?" Why not keep the isolation inside the function vs having to have the "parent" know about it?

DanKardell
Автор

So much helpful! but im still wonder ViewController is still not testable though you did dependency inhection cos you wanted to make VC testable. right?

wch
Автор

Thank you for this tutorial and coming back Youtube.
I am bit confused for the difference between Singleton and Dependancy Injection.
How does both deals with memory, can you differentiate?

rasheshbosamiya
Автор

Great informative video! Also that fade looks and fresh 😎

saitama
Автор

ur content has helped me so much now just gonna go and like all ur vids cos they are so helpful and amazing

matthewbird
Автор

Hey Kyle. If you do it programmatically, does that mean you can't do any UI work in the storyboard and you have to do everything programmatically?

davidruvinskiy
Автор

So, basically I can use it to send data to another VC?
I love segues, but I hate storyboards, so I needed to figure out how to send data. Notifications sadly not always work.
Thank you!

TheHyxD
Автор

I think the aversion to singletons may have a lot to do with how they can complicate coordinating with others on a team development effort, but, in the context of the lone coder, I'm in agreement. As for testability, why can't test components be built into the singleton class, to be invoked as part of tests of client (of the singleton) code. As for shared state, that's kind of the point. Sometimes you *want* shared state. That's why there are application delegate singletons, for example. It's just important to make sure that the state being shared is only what actually makes sense to be shared, not something specific to the client context.

cultibotics
Автор

What are your thoughts on things like SnapKit?

FailMachineInc
Автор

i keep getting error: Thread 1: Fatal error: init(coder:) has not been implemented

rdforte
Автор

what is init(nibName:, bundle:) and what is required init(), please list a resource that will explain me this kinda initialiser

yuvrajagarkar
Автор

Good explanation kilo loco @ kilo gram, lol 😂

nizzm
Автор

with storyboard you can use Object from Object Library and pass it in above of UIViewController representation in Storyboard. This Object will be subclass of SomeService

kav
Автор

can you share Complete Autolayout tutorial ?

naidubangaru
Автор

4:59 not your fault, Xcode's autocomplete is really, really, really, really dumb.

tomblah
Автор

So why not just use static properties and methods, instead of single instance properties and methods. That's partly a matter of aesthetics, and partly a matter of the conflation involved in doing so. Even if you only have a single instance of a class, you may still have use for class properties and methods. Say you don't need that singleton continuously available and want to free up the memory it occupies when it's not in use, and there's a small amount of state that needs to be preserved between instantiations; static properties can be used for that. Also, it probably would be better to make test code static and dedicate the single instance to just what it needs to interact with other code and just the state it needs to preserve between contexts.

cultibotics
visit shbcf.ru