I am trying to migrate the Visitor pattern from my (old) java code to swift. So far I have a generic FIFO (working fine).
protocol FiFo {
associatedtype U
func enqueue(_ : U)
func dequeue() -> U
}
I also want to tell the instance of the FIFO only to accept an instance of a visitor that uses the same type for the generic as the instance of the FIFO.
protocol Visitor {
associatedtype T
func processValue(_ value : T)
}
protocol FiFo {
associatedtype U
func enqueue(_ : U)
func dequeue() -> U
func visit(_ visitor : Visitor<U>)
}
Here I am facing:
Cannot specialize non-generic type 'Visitor'
Any hints? Thanks!