AppleGuice icon indicating copy to clipboard operation
AppleGuice copied to clipboard

Can't inject to UIViewController that is initialized with a storyboard

Open tomersh opened this issue 10 years ago • 0 comments

dependencies inside a UIViewController that is initialized with a storyboard are always null. The reason for that is that VCs that are created this way (not with [[UIViewController alloc] init]) never call init since they use initWithCoder: instead.

A tmp workaround is to add the following to a UIViewController that is used with storyboards.

-(instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [AppleGuice injectImplementationsToInstance:self];
    }
    return self;
}

tomersh avatar Nov 29 '14 18:11 tomersh