0

I have a collection of commands and some of them are ListCommands. But I'm struggling to filter them because I can't cast a Command to a ListCommand. Any help would be appreciated.

protocol Command {
  func evaluate()
}

protocol StringCommand: Command {
  var value: String { get }
}

protocol ListCommand: Command {
  assocatedType T
  var value [T] { get 
}

let commands: [Command] = object.execute()
let command = commands.first as? ListCommand // can only be used as a generic constraint
bobby123uk
  • 892
  • 4
  • 17

0 Answers0