Issue
I want to create a generic method in a specific class, where I can make a call to another class which based on the target (which conforms to specific protocol), can do certain calculations.
If I explicitly define what kind of target it is, it works okay, but if I want to pass it as type which conforms to a specific protocol, I run into trouble.
Not clear don't read
I have a protocol and a class which conforms to it as below:
protocol MyProtocol {
func someFunc()
}
class ConformingClass: MyProtocol {
func someFunc() {
// Do something
}
}
There is a class that I need to use:
class SomeClass<N: MyProtocol> {
class func doSomething() {
// Do something
}
}
And there is my class where I want to use the SomeClass but the type of it will be defined as a parameter on a method below:
class MyClass {
func doStuff<C: MyProtocol>(target: C.Type) {
SomeClass<target>.doSomething
}
}
Problem
Compilation error: 'target' is not a type
Question
How is that error possible, when I am explicitly saying that the parameter is a Type which conforms to MyProtocol? What am I doing wrong in here?
I am using Swift 2.3 and Xcode 7.3.1