Init protocol not found if a subclass is required for a generic class
I created a small example with generic logic and I don't understand what this error means. I think there is a definite problem with the designated initializer.
Hope someone has already dealt with this and can explain it to me.
protocol Test {
init(value: Int)
}
class ClassTest<T: Test> where T: UIView {
var t: T
init() {
t = T(value: 2) //error:
}
}
gives the following compiler error:
Argument labels '(value :)' do not match any available overloads
+3
source to share
2 answers
Try this hack now:
class ClassTest<T: Test> where T: UIView {
var t: T
init() {
// t = T(value: 2) // Compiler error!
t = create()
}
}
func create<T: Test>() -> T {
return T(value: 2)
}
I guess there is one more limitation of worrying about what happens to the compiler :-)
Is the compiler still broken? Check if this code succeeds to see if this error has been fixed.
+2
source to share