We want to change my architecture from MVC to VIPER. I read basic tutorial by following http://mutualmobile.github.io/blog/2013/12/04/viper-introduction/
source code link : https://github.com/mutualmobile/Counter
- (void)createScreen
{
CNTCountViewController* view = [[CNTCountViewController alloc] init];
CNTCountPresenter* presenter = [[CNTCountPresenter alloc] init];
CNTCountInteractor* interactor = [[CNTCountInteractor alloc] init];
view.presenter = presenter;//object
presenter.view = view;//protocol
presenter.interactor = interactor;
interactor.output = presenter;
self.window.rootViewController = view;
}
Where for communication from viewcontroller ---> presenter is via preseter's object and presenter --- > viewcontroller throught delegate (protocol). I think this is to avoid retain cycles.
But i also went through one more tutorial https://www.objc.io/issues/13-architecture/viper/ source code link :https://github.com/objcio/issue-13-viper
where he used protocols only for both direction in VTDListWireframe
- (void)presentListInterfaceFromWindow:(UIWindow *)window
{
VTDListViewController *listViewController = [self listViewControllerFromStoryboard];
listViewController.eventHandler = self.listPresenter;//protocol
self.listPresenter.userInterface = listViewController;//protocol
self.listViewController = listViewController;
[self.rootWireframe showRootViewController:listViewController
inWindow:window];
}
Here
1)What is the advantage of using protocols in both direction ?
2)I observed that both protocol references are with strong property declaration in both classes.won't it lead to retain cycle ?
1) If View(UIViewController) is released then whole module will be released.
https://medium.com/mobile-travel-technologies/architecting-mobile-apps-with-b-viper-modules-e94e277c8d68#.e4eh7c1l2
2) in VTDListWireframe, that listViewController is RootViewController so it won't be release so it won't lead to retain recycle. Just read these codes for idea imo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With