TieDad
TieDad

Reputation: 9929

xcode: How to hide this warning?

I imported ElementParser to my project in order to parse an html string. But xcode reports a warning at the following code:

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?

Upvotes: 0

Views: 206

Answers (1)

tom
tom

Reputation: 19163

Cast the object to id first.

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

@interface MyConnectDelegateClass : id<NSURLConnectionDelegate>

Upvotes: 2

Related Questions