Disons que j'ai ces protocoles:Puis-je faire une structure ou classe se conformer à un protocole générique plusieurs fois?
protocol Command {}
protocol CommandHandler
{
associatedtype T: Command
func handle(command: T) throws
}
Je voudrais faire une commande gestionnaire qui peut gérer plusieurs commandes, comme ceci:
class InventoryCommandHandler: CommandHandler
{
func handle(command: AddItemCommand) {
// do something
}
func handle(command: RemoveItemCommand) {
// do something
}
func handle(command: SomeOtherCommand) {
// do something
}
}
Mais quand j'essaie qu'il dit que InventoryCommandHandler n'est pas conforme au protocole CommandHandler. Y a-t-il un moyen de le faire?