initializing with 'Object *__strong' an expression of incompatible type 'id<Protocol>'

Question

Why does assigning an id extending a protocol to an object which also extends the same protocol produces the warning initializing with 'Object *__strong' an expression of incompatible type 'id' sometimes? I am not asking the way to suppress the warning.

@protocol PA <NSObject>

@end

@interface A1 : NSObject <PA>

@end

@interface A2 : NSManagedObject <PA> // Same for NSString in Xcode 8

@end



@protocol PB

@end

@interface B1 : NSObject <PB>

@end

@interface B2 : NSManagedObject <PB>

@end

A1 *a1 = (id<PA>)nil; // no warnings
A2 *a2 = (id<PA>)nil; // warning in Xcode 8. initializing with 'A2 *__strong' an expression of incompatible type 'id<PA>'

B1 *b1 = (id<PB>)nil; // warning in Xcode 8 and 7
B2 *b2 = (id<PB>)nil; // warning in Xcode 8 and 7

Show source
| xcode   | objective-c   | inheritance   | protocols   2017-01-03 11:01 0 Answers

Answers to initializing with &#39;Object *__strong&#39; an expression of incompatible type &#39;id&lt;Protocol&gt;&#39; ( 0 )

Leave a reply to - initializing with 'Object *__strong' an expression of incompatible type 'id<Protocol>'

◀ Go back