Quickly, you should use generics this way:
Given these examples of declarations of the protocol, main class, and subclass:
protocol ExampleProtocol { func printTest()
Now you want to define a method that accepts input parameters of type ATestClass (or child) that conforms to the ExampleProtocol protocol. Write a method declaration as follows:
func addFilter<T where T: ATestClass, T: ExampleProtocol>(newFilter: T) { println(newFilter) }
Your method overridden in swift should be
func addFilter<T where T:GPUImageOutput, T:GPUImageInput>(newFilter:T!) {
EDIT:
as your last comment example with generics in Enum
enum OptionalValue<T> { case None case Some(T) } var possibleInteger: OptionalValue<Int> = .None possibleInteger = .Some(100)
Specializes in compliance with the protocol:
enum OptionalValue<T where T:GPUImageOutput, T:GPUImageInput> { case None case Some(T) }
EDIT ^ 2:
you can use generics even with instance variables:
Let's say you have a class and an instance variable, you want this instance variable to accept only values ββof type ATestClass and match ExampleProtocol
class GiveMeAGeneric<T: ATestClass where T: ExampleProtocol> { var aGenericVar : T? }
Then create an instance like this:
var child = ATestClassChild() let aGen = GiveMeAGeneric<ATestClassChild>() aGen.aGenericVar = child
If child does not comply with ExampleProtocol protocol, it will not compile