【发布时间】:2021-02-22 18:27:15
【问题描述】:
我是 Clean VIP 架构的新手,我正在努力解决它的切入点。
(我只是放了一些代码)
视图控制器
protocol Delegate: class {
func execute()
}
class TitlesViewController:UIViewController {
weak var delegate: Delegate?
func viewDidLoad() {
super.viewDidLoad()
delegate.execute()
}
}
配置器
class TitlesConfigurator {
static func configureModule(viewController: TitlesViewController) {
let interactor = Interaction()
viewController.delegate = interactor
}
}
在 AppDelegate 中
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let titlesViewController = TitlesViewController()
let navigationController = UINavigationController(rootViewController: titlesViewController)
TitlesConfigurator.configureModule(viewController: titlesViewController)
window = UIWindow()
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
return true
}
现在我面临的问题是在TilesConfigurator 之外没有interactor 的引用,而delegate 是weak,这意味着它的总arc 为0。它导致delegate = nil 在@ 内987654330@
如何在我的架构中改进或解决此问题。
P.S:我认为在 ViewController 内部对委托进行强引用并不是一个好习惯
【问题讨论】:
标签: ios swift clean-architecture viper-architecture