在try 确定传入的对象的类型时,我收到以下编译器警告:
消息传递不合格ID
这是对大型Prod代码库中情况的简化:
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[ViewController myMethod:@"MyString"];
[ViewController myMethod:@[@(1), @(2), @(3)]];
[ViewController myMethod:@(13)];
}
+ (void)myMethod:(id)authenticationData {
if ([authenticationData isKindOfClass:[NSArray class]]) { // ERROR: 消息传递不合格ID
NSLog(@"NSArray");
} else if ([authenticationData isKindOfClass:[NSString class]]) { // No error here because the compiler stops checking after the first one. If above statement is commented out --> same error here
NSLog(@"NSString");
} else {
NSLog(@"Unknown");
}
}
@end