Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c xcode:如何隐藏此警告?_Objective C_Ios_Xcode - Fatal编程技术网

Objective c 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 因为第一行有一个检查,所以第

为了解析html字符串,我将ElementParser导入到我的项目中。但xcode在以下代码处报告警告:

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。