Dependency Injection | Swift 4, Xcode 9

  Рет қаралды 16,593

Kilo Loco

Kilo Loco

Күн бұрын

Пікірлер: 54
@edsergeev
@edsergeev 6 жыл бұрын
Underrated channel
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
If you truly believe that, then share the channel on any social media sites you have 😉
@KSwizzleDrizzle
@KSwizzleDrizzle 4 жыл бұрын
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!
@mattsanford5756
@mattsanford5756 6 жыл бұрын
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!
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
Yea, that’s going to also be covered in a video but I have to do more research to fully understand them. I’m struggling fully grasping how they work and trying to see how the factory pattern plays a role in it all. I do appreciate the comment though
@DanKardell
@DanKardell 2 жыл бұрын
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?
@abdurakhmonjamoliddinov7019
@abdurakhmonjamoliddinov7019 2 жыл бұрын
I think dependency injection grew because of test driven development, if you initialize inside functions then it's not very testable, one function needs this class and that class needs another one and on, but if you take it as function argument or initializer argument then you can test that function or that class alone by passing some dummy implementation, so basically if you want to test a function alone or some class alone then using dependency injection makes sense
@dev_jeongdaeri
@dev_jeongdaeri 4 жыл бұрын
Super cool finally I got what DI is
@ayon3527
@ayon3527 6 жыл бұрын
Good to see you man. Welcome back
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
Glad to be back!
@FailMachineInc
@FailMachineInc 4 жыл бұрын
What are your thoughts on things like SnapKit?
@rdforte
@rdforte 6 жыл бұрын
i keep getting error: Thread 1: Fatal error: init(coder:) has not been implemented
@saitama167
@saitama167 6 жыл бұрын
Great informative video! Also that fade looks and fresh 😎
@saitama167
@saitama167 6 жыл бұрын
Also when do we get T-Shirts??
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
Thanks! I was at a wedding yesterday so I had to look good 😎
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
T-shirts are already available Code Passionately T-Shirt www.amazon.com/dp/B07DWKMSX5/ref=cm_sw_r_cp_api_PpCoBbD2J5Z64
@wch0915
@wch0915 3 жыл бұрын
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?
@abdurakhmonjamoliddinov7019
@abdurakhmonjamoliddinov7019 2 жыл бұрын
yeah, ideally we would take protocol as argument and then we can provide some dummy implementation when testing
@yuvrajagarkar8942
@yuvrajagarkar8942 4 жыл бұрын
what is init(nibName: , bundle:) and what is required init() , please list a resource that will explain me this kinda initialiser
@LordStiltskin
@LordStiltskin 4 жыл бұрын
You can initialize objects from nib files. And you can pack such nibs in nsbundles. There, you’re specifying if you’re instantiating the superclass from a nib file in a bundle. The required initializer is a requirement set by the superclass so that your class can be saved to disk with nskeyedarchiver with all its properties and can be read and brought back to memory with the saved state (lets the instances of your class survive through app terminations). You can’t save all types to disk, so the compiler requires you to write how you convert your data to supported types. This is a quick, careless comment. Look up the stuff I mentioned and you’ll be able to figure it out.
@omrankhoja319
@omrankhoja319 3 жыл бұрын
Great explanation! Thank you!
@matthewbird8603
@matthewbird8603 6 жыл бұрын
ur content has helped me so much now just gonna go and like all ur vids cos they are so helpful and amazing
@rasheshbosamiya1482
@rasheshbosamiya1482 6 жыл бұрын
Thank you for this tutorial and coming back KZbin. I am bit confused for the difference between Singleton and Dependancy Injection. How does both deals with memory, can you differentiate?
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
In this tutorial I am showing how someone might use a singleton as the dependency they are using in their code. Not too sure about memory though
@rasheshbosamiya1482
@rasheshbosamiya1482 6 жыл бұрын
Kilo Loco okay
@TheHy6xD
@TheHy6xD 6 жыл бұрын
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!
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
Happy I could help
@abdurakhmonjamoliddinov7019
@abdurakhmonjamoliddinov7019 2 жыл бұрын
have you tried prepareForSegue?
@davidruvinskiy6347
@davidruvinskiy6347 5 жыл бұрын
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?
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
No, you can do it both in storyboards or programmatically. Hell you can even mix and match, I just wouldn't recommend it
@cultibotics
@cultibotics 6 жыл бұрын
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.
@sovanndyul7580
@sovanndyul7580 5 жыл бұрын
great explanation.
@naidubangaru3262
@naidubangaru3262 6 жыл бұрын
Excellent Tutorial
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
Thanks! Glad you liked it! 👍🏽
@naidubangaru3262
@naidubangaru3262 6 жыл бұрын
can you share Complete Autolayout tutorial ?
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
Not sure if I’m going to go down the autolayout path yet. I’m trying to focus on more advanced concepts while moving toward doing things programmatically
@AppalarajuPetaInfo
@AppalarajuPetaInfo 6 жыл бұрын
Kilo Loco that's great Thankyou
@TheAhmadReza
@TheAhmadReza 6 жыл бұрын
Why just don't use singletone?
@vamseeg1097
@vamseeg1097 4 жыл бұрын
Singleton is a tightly coupled and you can't test your code as DI usage, since state will change unexpectedly with tons of your classes.
@lubomir.o
@lubomir.o 6 жыл бұрын
awesome tutorial
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
Glad you like it!
@kav04
@kav04 6 жыл бұрын
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
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
Interesting! I will look into that approach as well
@nizz4m
@nizz4m 6 жыл бұрын
Good explanation kilo loco @ kilo gram, lol 😂
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
Glad you liked it 😁
@bngamebee4923
@bngamebee4923 6 жыл бұрын
thanks man
@tomblah
@tomblah 3 жыл бұрын
4:59 not your fault, Xcode's autocomplete is really, really, really, really dumb.
@andrewdavies5722
@andrewdavies5722 5 жыл бұрын
maaan... thank you
@cultibotics
@cultibotics 6 жыл бұрын
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.
@Kilo_Loco
@Kilo_Loco 6 жыл бұрын
Singletons were used in this example to refer to what most devs mean when they talk about dependency injection. While almost every person uses dependency injection in their code, there are a lot of devs that don’t understand what it really means and what is meant by the other devs that say singletons are bad. This is why I used singletons in this tutorial. Also, you won’t always be using your own objects as dependencies so you can’t control whether they are singletons or objects with static attributes on them.
@cultibotics
@cultibotics 6 жыл бұрын
Yes, I must confess that I'm among those who don't have a good handle on what's meant by dependency injection. I jumped on the tangential topic of singletons because it's something of a hot-button issue for me; I think singletons have gotten an underserved bad rap. In my admittedly naive view, they are sometimes the best, most appropriate solution, but, because of that bad rap, there isn't much discussion around how best to use them and how to avoid pitfalls. What does it mean to use a class when you only intend for there to be a single instance (at any given time), and how should its functionality be divided between static and instance code? What rules of thumb apply? kzbin.info/www/bejne/bpPRnYSNZaeZkM0
@abdurakhmonjamoliddinov7019
@abdurakhmonjamoliddinov7019 2 жыл бұрын
interesting, I never thought about using static except for constants, I feel like I am doing something wrong when I use them, maybe that's because of my lack of understanding of them
@cultibotics
@cultibotics 2 жыл бұрын
@@abdurakhmonjamoliddinov7019 The keyword "static" may have something to do with that. It's a little ugly, and a little misleading.
Use Closures Not Delegates | Swift 5, Xcode 10
14:52
Kilo Loco
Рет қаралды 24 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 913 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
Swift: Dependency Injection Tutorial (2022) - iOS
24:31
iOS Academy
Рет қаралды 35 М.
Singletons | Swift 4, Xcode 9
17:45
Kilo Loco
Рет қаралды 10 М.
Retain Cycles: How to Detect with Instruments Profiler!
13:55
Lets Build That App
Рет қаралды 50 М.
Start Using Lazy | Swift 5, Xcode 10
14:00
Kilo Loco
Рет қаралды 12 М.
Weak and Unowned Self Closure Memory Leak Fixes
12:21
Lets Build That App
Рет қаралды 57 М.
How to use the Coordinator pattern in iOS
18:12
Paul Hudson
Рет қаралды 73 М.
Dependency Injection in Swift
10:17
Cocoacasts
Рет қаралды 22 М.
Swift iOS Dependency Injection Tutorial
12:44
Code Pro
Рет қаралды 13 М.
Forget WiFi AGAIN! This Wireless Method is WAY Better?
12:05
GreatScott!
Рет қаралды 62 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН