我正在进行一些代码重构,但面临一个问题,即clang对这种情况没有任何警告:
@protocol CommonProtocol <NSObject>
- (void)common;
@end
=========
@interface Foo : NSObject <CommonProtocol>
- (void)foo;
@end
=========
@interface Bar : NSObject <CommonProtocol>
@end
=========
static id<CommonProtocol> getObject(void) {
return [Bar new];
}
Foo *casting = getObject(); /// ⚠️ there is no warning for this
[casting common];
[casting foo]; /// ???? crash because the casting object do not respond to '-foo'
我认为键入"Foo*"和"id<;CommondProtocol>;'不可互换,正在寻找一种方法来推广此警告.有没有编译标志来实现这一点?
NOTE:我try 了'-Weverything',但它仍然没有显示转换警告.