I am currently hard-coding another object directly when necessary, and I need the ability to use this through the init method (suppose?). In the code below, I create a new HatService in the viewDidLoad method, and I would prefer not to do this for validation / communication reasons.
- (void)viewDidLoad
{
[super viewDidLoad];
HatService* hatService = [[HatService alloc] init];
[hatService getHatById:self];
}
The first question is how to do this in objective-c? Second question. Should I worry about it or do it at all?
Update
Here's what I'm starting, but I never came across the first init method at runtime. I both declared in the interface - anything else that I missed that would allow me to override this init method and inject the service dependency?
. , , appDeleage , , ( , init?)
-(id)initWithHatService:(HatService *)service
{
if (self = [super init])
{
[self setService:service];
}
return self;
}
-(id)init
{
HatService* hatService = [[HatService alloc] init];
return [self initWithHatService:hatService];
}