警告:常量8与XXXX类型表达式的比较始终为false

时间:2012-12-21 02:44:50

标签: objective-c comparison warnings asihttprequest nsstream

我在项目中使用了ASIHTTPRequest,但在文件ASIDataCompressor.m190中使用了<{p}}

if ([inputStream streamStatus] == NSStreamEventErrorOccurred) {
        if (err) {
            *err = [NSError errorWithDomain:NetworkRequestErrorDomain code:ASICompressionError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Compression of %@ failed because we were unable to write to the destination data file at %@",sourcePath,destinationPath],NSLocalizedDescriptionKey,[outputStream streamError],NSUnderlyingErrorKey,nil]];
        }
        [compressor closeStream];
        return NO;
    }
它警告我:

Warning

任何人都知道如何修复它? THX

2 个答案:

答案 0 :(得分:17)

(NSStreamStatus)NSStreamEventErrorOccurred

修改

处理此问题的正确方法可能是将NSStreamEventErrorOccurred替换为NSStreamStatusError。这可能是ASIHTTP的作者想要的。

答案 1 :(得分:6)

NSStreamEventErrorOccurred的类型为NSStreamEvent,其常量值为8streamStatus方法返回NSStreamStatus而非NSStreamEventNSStreamStatus值不超过7值,这就是您收到错误的原因。你很幸运,8超出界限,你得到一个错误,因为并非总是如此,因此,你应该始终谨慎对待返回类型。