首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >代表式清洁VIP

代表式清洁VIP
EN

Stack Overflow用户
提问于 2021-02-22 18:27:15
回答 1查看 325关注 0票数 1

我是新来的清洁VIP架构,我正在努力与它的切入点。

(我只放了一点代码)

ViewController

代码语言:javascript
复制
protocol Delegate: class { 
   func execute()
}

class TitlesViewController:UIViewController {
   weak var delegate: Delegate?

   func viewDidLoad() {
         super.viewDidLoad()
         delegate.execute()
      }

}

配置器

代码语言:javascript
复制
class TitlesConfigurator {

static func configureModule(viewController: TitlesViewController) {
    let interactor = Interaction()
    
    viewController.delegate = interactor
    
   }
}

在AppDelegate中

代码语言:javascript
复制
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
}

现在,我面临的问题是,interactorTilesConfigurator之外没有引用,delegateweak,这意味着它的总arc是0。它导致了delegate = nil内部的viewDidLoad

如何在架构中改进或解决此问题。

P.S:我不认为在ViewController内部大力引用代表是不好的做法

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-22 18:38:46

这里的委托不应该是weak

代码语言:javascript
复制
var delegate: Delegate?

因为有一部分是weak,也就是let interactor = Interaction(),所以不会发生保留周期

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66321360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档