ios 带有 OR 条件的 Objective-C IF 语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10189809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Objective-C IF statement with OR condition
提问by Alberto Schiariti
What's wrong in this IF statement?
这个 IF 语句有什么问题?
if ([currentElement isEqualToString:@"aaa" || currentElement isEqualToString:@"bbb"])
XCode says:
XCode 说:
No visible @interface for 'NSString' declares the selector 'isEqualToString:isEqualToString:'
I'm into an NSXML Parser procedure if it can help, but I think it's not that the problem.
如果有帮助,我会使用 NSXML Parser 程序,但我认为这不是问题所在。
回答by Vladimir
You must compare result of two method calls:
您必须比较两个方法调用的结果:
if ([currentElement isEqualToString:@"aaa"] || [currentElement isEqualToString:@"bbb"])
The code you have actually compiles as
您实际编译的代码为
if ([currentElement isEqualToString:(@"aaa"||currentElement) isEqualToString:@"bbb"])
that is compiler tries to call non-existing isEqualToString:isEqualToString:
method of NSString
那是编译器试图调用isEqualToString:isEqualToString:
NSString 的不存在的方法