I have two protocols:
protocol Test {
func print()
}
protocol SpecifiedTest: Test {
func printSomethingElse()
}
I want to have an interface for all objects that have the variable conforming to Test
protocol TestHolder {
var test: Test! { get }
}
It works for all pure Test
variables
class SuccessClass: TestHolder {
var test: Test!
}
But when I try to use it with SpecifiedTest
I get
class FailureClass: TestHolder {
var test: SpecifiedTest!
}
Playground execution failed: error: MyPlayground.playground:13:11: error: type 'FailureClass' does not conform to protocol 'TestHolder'
class FailureClass: TestHolder {
^
MyPlayground.playground:2:13: note: protocol requires property 'test' with type 'Test!'; do you want to add a stub?
var test: Test! { get }
^
MyPlayground.playground:14:13: note: candidate has non-matching type 'SpecifiedTest!'
var test: SpecifiedTest!
Any ideas why is that?
Is there any way to do this without generics?
Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1), XCode Version 8.2.1 (8C1002)