Warning:Comparison of constant 8 with expression of type XXXX is always false
Asked Answered
S

2

8

I used ASIHTTPRequest in my project,but in the file ASIDataCompressor.m line 190:

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;
    }

it warning me this:

Warning

Any one know how to fix it? thx

Silverplate answered 21/12, 2012 at 2:44 Comment(0)
N
17

(NSStreamStatus)NSStreamEventErrorOccurred

edit

Probably the correct way to handle this is to replace the NSStreamEventErrorOccurred with NSStreamStatusError. That's probably what the author of ASIHTTP intended.

Neutralism answered 21/12, 2012 at 2:49 Comment(4)
really, this is probably poor API on the part of ASIHTTP. Also, if this is a new project, I know ASIHTTP has been obsoleted by its author, so you may want to consider alternatives, like AFNetwork. ASIHTTP is really full-featured, however.Neutralism
thank you,I will try to use AFNetwork.github.com/AFNetworking/AFNetworkingSilverplate
How can this answer be the accepted one!! this is just silencing the compiler when it's signaling an actual bug. Joe's answer is the right one, if you care that the code works as designed, that is.Jagannath
You're right it's a bug in ASIHTTP. I submitted a pull request to fix it. You might consider replacing NSStreamEventErrorOccurred with NSStreamStatusError instead. (Change ASIDataCompressor.m:164 ASIDataCompressor.m:190)Neutralism
P
6

NSStreamEventErrorOccurred is of type NSStreamEvent with a constant value of 8. The streamStatus method returns an NSStreamStatus not NSStreamEvent and NSStreamStatus values do not exceed a value of 7 which is why you got the error. You were fortunate that 8 exceeded the bounds and you got an error because that not is always the case, therefore, you should always be cautious of the return type.

Pastille answered 21/12, 2012 at 2:49 Comment(1)
> and NSStreamStatus values do not exceed a value of 7 < - Ah, this is the issue for me. Xcode, now very Swifty, is displaying the warning as if the enum is exhaustive. But the Objective-C API is happily returning results that are outside the range of the declared public enum. In my case it's NSEventSubtype.Collis

© 2022 - 2024 — McMap. All rights reserved.