Home > Software engineering >  How to declare a protocol with a function that returns NavigationLink
How to declare a protocol with a function that returns NavigationLink

Time:12-22

I want to declare a protocol that has function which must return NavigationLink. But when I try this it returns an error "Reference to generic type 'NavigationLink' requires arguments in <...>"

protocol Protocol: class{
    func function() -> NavigationLink
}

(Jessy)

class BeersListRouter: BeersListRouterProtocol{
    typealias Label = Text
    typealias Destination = View
    
    func getBeerDetailsView(for beer: Beer) -> NavigationLink<Label, Destination>{
        
    }
}

CodePudding user response:

NavigationLink is a generic type, with two placeholders. You need to account for them.

protocol Protocol: AnyObject {
  associatedtype Label: View
  associatedtype Destination: View
  
  func function() -> NavigationLink<Label, Destination>
}
  • Related