I have a protocol (ProtocolA) containing one property corresponding to the second protocol (ProtocolB).
public protocol ProtocolA {
var prop: ProtocolB? { get }
}
public protocol ProtocolB {
}
I am trying to declare two classes that will implement them:
private class ClassA : ProtocolA {
var prop: ClassB?
}
private class ClassB : ProtocolB {
}
But I get an error message:
Type 'ClassA' does not conform to protocol 'ProtocolA'
A protocol requires a prop property of type ProtocolB?
Candidate has inconsistent type "ClassB?"
Which is annoying because ClassB conforms to protocol B.
in the good old, I would just declare the property as:
@property (nonatomic) ClassB <ProtocolB> *prop;
but the only way, apparently, I can get around this quickly by adding ivar as:
private class ClassA : ProtocolA {
var _prop: ClassB?
var prop: ProtocolB? { return _prop }
}
Is there no way around this?