appsquickly / typhoon

Powerful dependency injection for Objective-C ✨✨ (https://PILGRIM.PH is the pure Swift successor to Typhoon!!)✨✨
https://pilgrim.ph
Apache License 2.0
2.7k stars 270 forks source link

Multiple instances injected into view controller when using storyboard reference #599

Closed sergkovb closed 5 years ago

sergkovb commented 5 years ago

There is a problem with multiple property injection when detail view controller is loaded via a storyboard reference

Снимок экрана 2019-03-13 в 15 17 00
2019-03-13 15:11:16.919842+0300 TyphoonIssue[21295:445597] FirstViewController.initWithCoder
2019-03-13 15:11:16.924133+0300 TyphoonIssue[21295:445597] Model.init
2019-03-13 15:11:16.924500+0300 TyphoonIssue[21295:445597] FirstViewController.setModel: self = <FirstViewController: 0x7fefecb03800>, model = <Model: 0x60000249e560>
2019-03-13 15:11:20.583246+0300 TyphoonIssue[21295:445597] SecondViewController.initWithCoder
2019-03-13 15:11:20.583561+0300 TyphoonIssue[21295:445597] Model.init
2019-03-13 15:11:20.583764+0300 TyphoonIssue[21295:445597] SecondViewController.setModel: self = <SecondViewController: 0x7fefeae22b20>, model = <Model: 0x60000249e9c0>
2019-03-13 15:11:20.584012+0300 TyphoonIssue[21295:445597] Model.init
2019-03-13 15:11:20.584163+0300 TyphoonIssue[21295:445597] SecondViewController.setModel: self = <SecondViewController: 0x7fefeae22b20>, model = <Model: 0x6000024b8180>

https://github.com/sergkovb/Typhoon-issue

There is a similar problem here https://github.com/appsquickly/Typhoon/issues/505

sergkovb commented 5 years ago

I suggest we fix the bug this way https://github.com/appsquickly/typhoon/pull/600

I added this condition

if (storyboard && viewController.storyboard && ![viewController.storyboard isEqual:storyboard]) {
return;
}

to TyphoonViewControllerInjector.m

and added tests for this issue and #505

alexgarbarev commented 5 years ago

Thanks @sergkovb, your changes were deployed as 4.0.8 to CocoaPods.