我是新来的清洁VIP架构,我正在努力与它的切入点。
(我只放了一点代码)
ViewController
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内部大力引用代表是不好的做法
发布于 2021-02-22 18:38:46
这里的委托不应该是weak
var delegate: Delegate?因为有一部分是weak,也就是let interactor = Interaction(),所以不会发生保留周期
https://stackoverflow.com/questions/66321360
复制相似问题