【发布时间】:2018-07-04 01:28:48
【问题描述】:
我正在尝试重构一个应用程序,以便为核心数据堆栈使用依赖注入。
这里有一个很好的解释: http://cleanswifter.com/dependency-injection-with-storyboards/
我的问题是,在我的应用程序中,由 uittabbarcontroller 链接的视图控制器嵌入在导航控制器中,所以这段代码:
if let tab = window?.rootViewController as? UITabBarController {
for child in tab.viewControllers ?? [] {
if let top = child as? PersistenceStackClient {
top.set(stack: persistenceStack)
}
}
}
从未见过他们。
我的直觉是,我需要将 for child in 更改为引用导航控制器子级的内容,但所有尝试都失败了。
我想我需要一些类似的东西:
for child in tab.navigationController?.viewControllers
但这似乎没有任何作用。
【问题讨论】:
标签: swift core-data uitabbarcontroller