问题描述
我是 Clean VIP Architecture 的新手,我正在努力寻找它的入口点。
(我只是放了一些代码)
视图控制器
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
}
现在我面临的问题是在 interactor
之外没有 TilesConfigurator
的引用,delegate
是 weak
,这意味着它的总 arc
是0. 它导致 delegate = nil
内 viewDidLoad
如何改进或修复我的架构中的这个问题。
P.S:我认为在 ViewController
解决方法
代表不应weak
在这里
var delegate: Delegate?
因为有一部分是 weak
是 let interactor = Interaction()
所以不会发生保留循环