我们想将我的架构从 MVC 更改为 VIPER。我按照http://mutualmobile.github.io/blog/2013/12/04/viper-introduction/阅读了基本教程
源代码链接: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;
}
来自视图控制器的通信 ---> 演示者是通过预设器的对象和演示者 --- > 视图控制器通过委托(协议)。我认为这是为了避免保留周期。
但我还浏览了另一个教程https://www.objc.io/issues/13-architecture/viper/ 源代码链接:https ://github.com/objcio/issue-13-viper
他在 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];
}
这里
1)双向使用协议有什么好处?
2)我观察到两个协议引用在两个类中都具有强属性声明。它不会导致保留周期吗?