我是Clean VIP Architecture的新手,我正在为它的切入点而挣扎。
(我只放了一些代码)
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
}
}
在AppDelegatefunc 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。结果是viewDidLoad
里面有delegate = nil
我如何改进或修复我的架构中的这个问题。
p。S:我不认为在ViewController
内部对委托做一个强引用是好的做法
Delegate不应该是weak
var delegate: Delegate?
因为有一部分是weak
也就是let interactor = Interaction()
所以不会出现保留循环