Ios 使用SwiftUI从线框创建新的VIPER模块
我正在尝试使用SwiftUI实现VIPER。首先,我从线框返回UIKit VC(UIHostingController(rootView)),直到我意识到在导航中,当演示者告诉线框显示快速UI视图时,我无法通过NavigationLink传递UIViewController 有了这个问题,我试图使线框协议返回SwiftUI“视图”,但这似乎是不可能的(协议“视图”只能用作一般约束,因为它具有自身或关联的类型要求):Ios 使用SwiftUI从线框创建新的VIPER模块,ios,swift,swiftui,viper,Ios,Swift,Swiftui,Viper,我正在尝试使用SwiftUI实现VIPER。首先,我从线框返回UIKit VC(UIHostingController(rootView)),直到我意识到在导航中,当演示者告诉线框显示快速UI视图时,我无法通过NavigationLink传递UIViewController 有了这个问题,我试图使线框协议返回SwiftUI“视图”,但这似乎是不可能的(协议“视图”只能用作一般约束,因为它具有自身或关联的类型要求): 如何定义返回SwiftUI“视图”的函数?您的Presenter类应该具有视图实
如何定义返回SwiftUI“视图”的函数?您的Presenter类应该具有视图实现的协议变量。 因此,假设您的
演示者
实现了模块输入
和模块输出
协议,在类型视图输入协议
上有两个变量,在类型路由器输入协议
上有一个变量
所以你们的路由器输入类和路由器应该是这样的
protocol RouterInput {
func routeToAnotherView(from view: ViewInput)
}
class Router: RouterInput {
func routeToAnotherView(from view: ViewInput){
guard let viewInMyType = view as? MyType else {
return
}
// Now you can go to your view
}
}
在presenter中,您将使用参数your
View
protocol outlet调用函数。我已经解决了这个问题,返回了一个“HomeViewProtocol”,而不是一个视图。。。我的HomeView符合HomeViewProtocol,当然是一个快速UI视图
protocol RouterInput {
func routeToAnotherView(from view: ViewInput)
}
class Router: RouterInput {
func routeToAnotherView(from view: ViewInput){
guard let viewInMyType = view as? MyType else {
return
}
// Now you can go to your view
}
}