如何解决使用委托模式清理 VIP
我是 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()
所以不会发生保留循环
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。