Swift Dependency Injection - What is it? What are the benefits?

preview_player
Показать описание

Dependency Injection is when you give an object what it needs, rather than it creating those objects itself. In this video I show you a basic example using the Chipotle App as an example. And then I help you answer the common iOS Dev interview questions asking why would you use dependency injection in Swift and what are the benefits.

This tutorial was created using Xcode 14 and iOS 16.

My iOS Dev Courses:

iOS Developer Interview Questions Playlist:

Twitter:

Book and learning recommendations that help out the channel if you decide to purchase (Affiliate Links):

Paul Hudson's Hacking With Swift:

Donny Wals - Combine:

Mark Moeyken’s SwiftUI Books:

#swift #softwaredeveloper #iosdeveloper

Timestamps:
0:00 - What is Dependency Injection
0:26 - Initializer Injection Code Example
4:19 - Benefits of Dependency Injection
Рекомендации по теме
Комментарии
Автор

Somehow I ended up being the first view of this video. I started as an iOS developer following Sean's interview videos 5 years ago, I ended up being a Backend/Cloud developer now. by viewing this video I realize how much I changed and how much Sean's video got better over the time. Keep it up Sean, looking at these swift videos make me want to switch back somehow to iOS developement.

merouanebboy
Автор

Perfect timing for this example. I just had Chipotle today. That double meat chicken al pastor was good. 😋

JasonMitchellAZ
Автор

Great vid! Nice to confirm what I thought I understood with better words. BTW, I like the very short simple code technique so we can focus on the theory.

tchendoh
Автор

you know what, Sean you are awesome. I was confused about what dependency injection was until the first 20 seconds of the video. Can't thank you enough!!

teaberry
Автор

Great video as always Sean, just one thing in the company I work we prefer to use the init injection instead of the property wrapper that Resolver provides, don’t get me wrong the property wrapper work fine and it’s probably easier, but we prefer the init to avoid couple our app to that library in case anything went wrong and the library stops working, in the case that happen we just can remove it and continue working with initializers.

cristopherescorcia
Автор

Absolutely fantastic video as usual, would have been even more valuable for me if you had more content on the "easier testing" I use the dependency injection to pass my view models across different views, but never quite had the practice to use it for "easier tests", as I always just use the simulator build, not llb debugging, but would have ben great to learn more about that. Thanks for the great content as usual!

captainmichaelj
Автор

Hi, updating xcode to 14.3 i receive the log "[PipelineLibrary] Mapping the pipeline data cache failed, errno22" when adding the MapView in the viewcontroller. I Receive this error only when i test on a real device not in the simulator. Can i fix it ? Is a common problem? Thanks for the time I appreciate so much.

vittyfiorentini
Автор

Is there any downside by creating the new object directly when passing it to the child class? like this... `let viewModel = NetWorkManager(), bag: Bag())` Less code. Thanks a lot for all of your videos.

fsdolphin
Автор

What is the difference between this and Combine's @EnvironmentObject? Isnt it good to use that wrapper instead of using parameters? I am confused sometimes about that.

ahmetbugraozcan
Автор

@Sean Allen, why not to pass VM's via .environmentObject?

bonifacy
Автор

5 years ago I started learning SWIFT and it was the worst decision in my life, this market is so small for juniors that it was such a big waste of my time today I am devops with python/bash etc and I am very happy with that .


I remember like I was learning from you videos, liked it but the market overall is shitty in my honest opinion, especially like technology like REACT evolved and would not recommend to anybody go to the mobile sector.
It was very good in the begining, today its time of cloud/security/devops/ai not mobile apps.

smarter
Автор

Let’s not normalize ‘ER’ names like Manager. It represents a lack of understanding of the actual domain.

Also, what Apple is calling Protocol Oriented Programming, is actually just Object Oriented Programming as Protocols (Interfaces in Java) represent Roles in OOP.

An object should have a dependency on some sort of Role that it defines, which will also help with naming!

brandtdaniels
Автор

the video explain what is dependency injection but do not talk about wrappers etc... I was expecting a video that show a concrete implementation

cedricloneux