Okay, I looked at this excellent answer, but I don't think it applies to my issue (but maybe it does, and I'm just being obtuse).
The issue is that I want to set up an Array of dispatcher objects, based on a protocol (not a base class), so the Array would be an Array of protocol, like so:
protocol ProtoOne { func someFunc() }
protocol ProtoTwo: ProtoOne { }
class ClassBasedOnOne: ProtoOne { func someFunc() { /* NOP */} }
class AnotherClassBasedOnOne: ProtoOne { func someFunc() { /* NOP */} }
class ClassBasedOnTwo: ProtoTwo { func someFunc() { /* NOP */} }
class AnotherClassBasedOnTwo: ProtoTwo { func someFunc() { /* NOP */} }
let arrayOfInstances: [ProtoOne] = [ClassBasedOnOne(), AnotherClassBasedOnOne(), ClassBasedOnTwo(), AnotherClassBasedOnTwo()]
Simple enough, eh?
But then, I want to filter for only certain instances, based on their protocol, not their class. With a function signature like this:
func getInstancesOfProtoTwo(from: [Any]) -> [ProtoTwo] { return [] }
or maybe a more generic type, like so:
func filterForInstances<T>(of: T.Type, from: [Any]) -> [T] { return [] }
I'm kind of at a loss as to how to do this. Is it even possible?
I have a nasty suspicion that it's actually incredibly simple, and I'm missing the forest for the trees.