Imagine I have two protocols:
@protocol A
@end
and
@protocol B <A> // Protocol B conforms to protocol A.
@end
And also two variables:
id<A> myVar = nil;
and
id<B> otherVar = //correctly initialized to some class that conforms to <B>;
Then, why can’t I assign ‘otherVar’ to ‘myVar’?
myVar = otherVar; //Warning, sending id<B> to parameter of incompatible type id<A>
Thanks!
Is the protocol’s (
B) declaration (not just its forward declaration) visible? And does the declaration precedemyVar = otherVar;?When the declaration order is correct, clang did not complain.
To illustrate:
whereas the properly ordered version produces no warning: