[英]Clean VIP with Delegate Pattern
I am new to Clean VIP Architecture and I am struggling with its entry point.我是 Clean VIP Architecture 的新手,我正在努力解决它的切入点。
(I am only putting some bit of code) (我只是放一些代码)
ViewController视图控制器
protocol Delegate: class {
func execute()
}
class TitlesViewController:UIViewController {
weak var delegate: Delegate?
func viewDidLoad() {
super.viewDidLoad()
delegate.execute()
}
}
Configurator配置器
class TitlesConfigurator {
static func configureModule(viewController: TitlesViewController) {
let interactor = Interaction()
viewController.delegate = interactor
}
}
In AppDelegate在 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
}
Now Issue that I am facing is that there is no reference of interactor
outside of TilesConfigurator
and delegate
is weak
which means its total arc
is 0. It results in delegate = nil
inside viewDidLoad
现在我面临的问题是
TilesConfigurator
之外没有interactor
器的引用,并且delegate
weak
,这意味着它的总arc
为 0。它导致viewDidLoad
内的delegate = nil
How can I improve or fix this issue in my architecture.如何在我的架构中改进或解决此问题。
PS: I don't think its good practice to make a strong reference of delegate inside ViewController
PS:我不认为在
ViewController
中对委托进行强引用是一种好的做法
Delegate shouldn't be weak
here代表在这里不应该
weak
var delegate: Delegate?
As there is one part that's weak
which is let interactor = Interaction()
so no retain cycles will occur因为有一个部分
weak
,它是let interactor = Interaction()
所以不会发生保留周期
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.