⚠️ 23 June 2020 Edit: From Xcode 12, both switch and if let statements will be supported in the ViewBuilder!
我一直在try 用SwiftUI复制我的一个应用程序.它有一个RootViewController,它根据枚举值显示不同的子视图控制器.在"我的视图"中,我们使用的是以下代码,而不是"我的视图"中的控制器:
struct RootView : View {
@State var containedView: ContainedView = .home
var body: some View {
// custom header goes here
switch containedView {
case .home: HomeView()
case .categories: CategoriesView()
...
}
}
}
不幸的是,我收到了一个警告:
Closure containing control flow statement cannot be used with function builder 100
那么,有没有其他方法可以切换,这样我就可以复制这种行为?