I have two protocols Valid and Resetable and an array of inputViews that is of type [Valid]. That all works fine. So now I've got my Resetable protocol:
protocol Resetable: class {
func reset()
}
Now, everything inside of inputViews also conforms to the Resetable protocol, so what I want to do is basically loop through and call reset() on each member. If I do this then it will work:
for input in inputViews {
(input as! Resetable).reset()
}
But i've extended Array with the following:
extension Array where Element:Resetable {
func resetAll() {
forEach({ $0.reset() })
}
}
So what I really want to be able to do is downcast inputViews entirely and call resetAll().
I tried:
let resetableViews = inputViews.map({ $0 as! Resetable })
resetableViews.resetAll()
But it says Using Resetable as a concrete type conforming to Resetable is not supported
How can I achieve this by using resetAll()?