简体   繁体   English

xcode:如何隐藏此警告?

[英]xcode: How to hide this warning?

I imported ElementParser to my project in order to parse an html string. 我将ElementParser导入到我的项目中以解析html字符串。 But xcode reports a warning at the following code: 但xcode在以下代码中报告警告:

if ([connectionDelegate respondsToSelector:@selector(connection:didFailWithError:)])
    [connectionDelegate connection:connection didFailWithError: error]; // Warning at this line

Since the first line has a check, the second must be safe at runtime. 由于第一行有一个检查,第二行必须在运行时是安全的。

I really don't like warnings to exist in my project. 我真的不喜欢在我的项目中存在警告。 So I wonder if there is anyway to hide this warning? 所以我想知道是否还有隐藏这个警告?

Cast the object to id first. 首先将对象转换为id

if ([connectionDelegate respondsToSelector:@selector(connection:didFailWithError:)])
    [(id)connectionDelegate connection:connection didFailWithError: error];

Or, better yet, as @Rob suggests, for the @interface declaration of your connectionDelegate's class, add the following 或者,更好的是,正如@Rob建议的那样,对于connectionDelegate类的@interface声明,添加以下内容

@interface MyConnectDelegateClass : id<NSURLConnectionDelegate>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM