Swift iOS Dependency Injection Tutorial

preview_player
Показать описание
Check out my new full length iOS course:

In this tutorial we will break down the dependency injection design pattern. We will learn what dependency injection is, the benefits gained from applying dependency injection, and go over a few examples of bad code and how we can improve that code using dependency injection.

If you are new to iOS development and would like to learn from a more in depth course make sure to check out my iOS Development Fundamentals Course below which contains 20 video tutorials and over 3 hours of video tutorial content where we build an app from scratch.

#CodePro #iOS #Swift #Programming

--
50% off iOS Development Fundamentals Course on Udemy:

or use CODEPRO999 for 50% off the course price.

--

Useful Learning Resources

--

Check out some of the apps I've built:

--

Follow Code Pro on:

If you found this tutorial helpful please like the video, share the video, and subscribe to CodePro. You can follow CodePro on Twitter, Facebook, for the latest channel news and updates.
Рекомендации по теме
Комментарии
Автор

Moving on into design pattern tutorials the first topic I'd like to break down is dependency injection. Dependency injection is a big fancy word for a very simple concept. Dependency injection can greatly improve the quality and safety of your code and is very simple to apply and start using. See if you can apply this concept in your code and projects.

CodePro
Автор

This is the 6th or 7th Video I'm watching and this by far the best explanation....

RajrkSunny
Автор

At last... someone that doesn't complicate a simple thing to explain... good job!

vladimirsukanica
Автор

This tutorial deserves to take a LIKE because it's one of the less well-explained what DI is.

dimitardimitrov
Автор

Best DI explanation I came across. You really put yourself in the mindset of a beginner which others often don’t do. Thanks for explaining every little aspect :)

amaancan
Автор

Great video..I see that you are using quicktime player to create the video. How have you integrated voice over on that? Is that through post-editing?

richadua
Автор

Thanks a ton Code Pro... This was neat... Could you please teach us Protocol Oriented Programming in action ? I would love to learn and use it. Thank you.

kevinvishal
Автор

Constructor Initializing the classes is called Dependency injection. Is that it?

ushadesai
Автор

I see. I had been doing this forever. Was wondering why it wasn’t declared like this since the beginning but I understand that’s the name of this coding pattern. Thank you for the video.

RyuuzakiJulio
Автор

I'm learning about Unit Testing for network, and this tutorial helped me a lot... Thank you so much

rikirokhman
Автор

Hello from Brazil 🇧🇷
Thank you for this excellent class.

JacksonSmith
Автор

Very nice explanation along with clear, real-world examples on implementation.

TokyoXtreme
Автор

Property Injection is also a type of Dependency Injection.

hackj
Автор

Basically, just use a constructor/initializer...

petersuvara
Автор

why not use Interface class in depency injection, I mean do like this (if you have some better solutions, please share me. I also want to learn something new from each other):

***interface I do like this:
@interface MainMenuController ()

@property (nonatomic) id<IICloudManager> icloudManager;
@property (nonatomic) id<IGlobalSettingManager> globalSettingManager;
@property (nonatomic) id<ILocalValueManager> localValueManager;
@property (nonatomic) id<IIAPHelper> iIAPHelper;

@end


*** I construct like this:

-(void)Di:


localValueManager
{

_localValueManager = localValueManager;
_icloudManager = cloudManager;
_icloudManager.delegate = self;

_globalSettingManager = globalSettingManager;

_iIAPHelper = iIAPHelper;
}

*** I inject like this:


id<ILocalValueManager> localValueManager = [[LocalValueManager alloc] init];
id<IGlobalSettingManager> globalSettingManager = [[GlobalSettingManager alloc] init];
id<IICloudManager> icloudManager = [[ICloudSourceManager alloc] init];

NSSet * productSet = [NSSet setWithObjects:kInAppPurchase_litle, nil];

id<IIAPHelper> iIAPHelper = [[IAPHelper alloc]

[self Di:icloudManager


iIAPHelper:iIAPHelper];

***This is a protocol class I use to define Interface class:

@protocol ICloudManagerDelegate <NSObject>

-(void)startUpdateICloudData;
-(void)endUpdateICloudData;

@end

@protocol IICloudManager <NSObject>

@property (nonatomic, weak) id<ICloudManagerDelegate> delegate;

-(BOOL)isConnectToICloud;

-(NSDictionary *)getInventoryCommonObjArr;
- (NSArray *)getShohinCommonObjArr;
- (NSArray *)getSokoCommonObjArr;
- (NSArray *)getTantoCommonObjArr;
- (NSArray *)getTokuCommonObjArr;
-(CommonObj *)textTofind;

-(NSDate *)name;
-(NSArray *)getAllFileName;
-(void)setFileName:(NSString *)fileName forKey:(NSString *)key;
-(BOOL)isFileMatch:(NSString *)fileName mode:(MainVcMode)mode;

@end


***And I do like this:

@interface ICloudSourceManager : NSObject <IICloudManager>



@end

letri
welcome to shbcf.ru