简体   繁体   中英

iOS7 comparison of constant with expression is always false

In my app that works on iOS 5 and 6 I have an if statement:

NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:sourcePath];
if ([inputStream streamStatus] == NSStreamEventErrorOccurred){
[...]
}

On iOS 7 I get the following warning:

 Comparison of constant 'NSStreamEventErrorOccurred' with expression of type 
'NSStreamStatus' (aka 'enum NSStreamStatus') is always false

Any ideas on what's changed on iOS 7 regarding NSInputstream class? I would like to know why do I receive this warning now on iOS7.

iOS 7 is more particular with enum comparisons. The issue is that you're comparing an NSStreamStatus enumerated value to another, unrelated NSInputStreamEvent value. Instead, try:

NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:sourcePath];
if ([inputStream streamStatus] == NSStreamStatusError){
    [...]
}

This issue has nothing to do with iOS 7 per se, it's just an existing issue you've now discovered thanks to more meticulous warnings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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