0

HTML文字列を解析するために、ElementParserをプロジェクトにインポートしました。ただし、xcodeは次のコードで警告を報告します。

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

最初の行にはチェックがあるため、2番目の行は実行時に安全である必要があります。

プロジェクトに警告が存在するのは本当に好きではありません。それで、この警告を隠す方法があるのだろうか?

4

1 に答える 1

2

idオブジェクトを最初にキャストします。

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

または、さらに良いことに、@ Robが示唆しているように、connectionDelegateのクラスの@interface宣言には、次を追加します。

@interface MyConnectDelegateClass : id<NSURLConnectionDelegate>
于 2012-12-20T02:04:13.897 に答える