I am trying to make a protocol that has has two associated types. One of these associated types is for a delegate. When I try to use another protocol as the associated type, I get the error "Type 'HostConnectionService' does not conform to protocol 'ConnectionService'". The code I have is written below:
protocol ConnectionService: class {
associatedtype Peer: Sharelist.Peer
associatedtype Delegate: ConnectionServiceDelegate
var connectedPeers: [Peer] { get }
var delegate: Delegate? { get }
}
protocol ConnectionServiceDelegate { }
// Error
class HostConnectionService: NSObject, ConnectionService {
typealias Peer = GuestPeer
typealias Delegate = HostConnectionServiceDelegate
var delegate: HostConnectionServiceDelegate?
var connectedPeers: [GuestPeer] = []
}
protocol HostConnectionServiceDelegate: ConnectionServiceDelegate { }
When I change the line
typealias Delegate = HostConnectionServiceDelegate
to be of a non-protocol type, I no longer get an error:
struct NonProtocolConnectionServiceDelegate: ConnectionServiceDelegate { }
// No Error
class HostConnectionSertice: NSObject, ConnectionService {
...
typealias Delegate = NonProtocolConnectionServiceDelegate
...
}
Is this a fundamental Swift limitation, or am I doing something wrong?