Objective c xcode:如何隐藏此警告?
为了解析html字符串,我将ElementParser导入到我的项目中。但xcode在以下代码处报告警告:Objective c xcode:如何隐藏此警告?,objective-c,ios,xcode,Objective C,Ios,Xcode,为了解析html字符串,我将ElementParser导入到我的项目中。但xcode在以下代码处报告警告: if ([connectionDelegate respondsToSelector:@selector(connection:didFailWithError:)]) [connectionDelegate connection:connection didFailWithError: error]; // Warning at this line 因为第一行有一个检查,所以第
if ([connectionDelegate respondsToSelector:@selector(connection:didFailWithError:)])
[connectionDelegate connection:connection didFailWithError: error]; // Warning at this line
因为第一行有一个检查,所以第二行在运行时必须是安全的
我真的不喜欢在我的项目中出现警告。因此,我想知道是否还有隐藏此警告的方法?首先将对象强制转换为
id
if ([connectionDelegate respondsToSelector:@selector(connection:didFailWithError:)])
[(id)connectionDelegate connection:connection didFailWithError: error];
或者,更好的是,正如@Rob所建议的,对于您的ConnectionLegate类的@interface声明,添加以下内容
@interface MyConnectDelegateClass : id<NSURLConnectionDelegate>
@interface MyConnectDelegateClass:id
是否可以使用协议?如果正确键入了connectionelegate
(符合正确的协议),并且该协议中的connection:didFailWithError:
方法是可选的,则上述操作不应产生警告。什么类型是connectionelegate
<代码>id<代码>id?还有什么吗?因为代码来自githut,不是我自己写的,我不想修改任何行,或者修改尽可能少的行。或者更好,首先定义connectionLegate
。@Rob,同意!我只在有限的情况下使用id
cast。