如何使用 returns NavigationLink 的函数声明协议
How to declare a protocol with a function that returns NavigationLink
我想声明一个具有必须 return NavigationLink 功能的协议。但是当我尝试这样做时 return 出现错误“对泛型类型 'NavigationLink' 的引用需要 <...> 中的参数”
protocol Protocol: class{
func function() -> NavigationLink
}
(杰西)
class BeersListRouter: BeersListRouterProtocol{
typealias Label = Text
typealias Destination = View
func getBeerDetailsView(for beer: Beer) -> NavigationLink<Label, Destination>{
}
}
NavigationLink is a generic type, with two placeholders。你需要考虑到它们。
protocol Protocol: AnyObject {
associatedtype Label: View
associatedtype Destination: View
func function() -> NavigationLink<Label, Destination>
}
我想声明一个具有必须 return NavigationLink 功能的协议。但是当我尝试这样做时 return 出现错误“对泛型类型 'NavigationLink' 的引用需要 <...> 中的参数”
protocol Protocol: class{
func function() -> NavigationLink
}
(杰西)
class BeersListRouter: BeersListRouterProtocol{
typealias Label = Text
typealias Destination = View
func getBeerDetailsView(for beer: Beer) -> NavigationLink<Label, Destination>{
}
}
NavigationLink is a generic type, with two placeholders。你需要考虑到它们。
protocol Protocol: AnyObject {
associatedtype Label: View
associatedtype Destination: View
func function() -> NavigationLink<Label, Destination>
}