protocol ScannerDelegate {
func outputReceived(_ s: String)
}
protocol ScoreboxDelegate {
func outputReceived(_ s: String)
}
class SessionHandler : ScannerDelegate, ScoreboxDelegate {
let scanner = Scanner()
let scorebox = Scorebox()
init() {
// scanner.delegate is of type ScannerDelegate?
scanner.delegate = self
// scorebox.delegate is of type ScoreboxDelegate?
scorebox.delegeate = self
}
// I need to implement two different outputReceived() functions,
// or know whether I'm being called because I'm a scanner delegate,
// or a scorebox delegate.
// Now what?
}
I would like my SessionHandler class to be able to conform to both classes, set itself as a delegate of both classes, and implement two very different methods for the required outputReceived() function.
How do I do this?
Do I have to contact the author of one of the delegates and convince them to change the name of their required method?
FWIW, I believe the issue you're running into is the very reason that most delegate methods provided by Apple include the sender's type as part of the method name (so that a single type can witness multiple delegates without conflicting). The other reason being that it provides a place for the sender to be passed in (so that, similarly, an object can witness the same delegate for multiple instances of the sender's type).
The collision you're hitting is why it's a good idea for folks designing their own APIs to follow these well-established design patterns.