开发者

OR function in Objective-C

is there an OR function in Objective-C?

for example:

if(string1 == string2 || string开发者_StackOverflow3 == string 4)

|| doesnt seems to work.

Thanks.


|| is a valid Objectivc-C and C Operator. It should work.

Try is code:

if([string1 isEqualToString:string2] || [string3 isEqualToString:string4]) 
{
}


The or-operator || works fine, but the == operator doesn't work for C-strings nor for NSString if you want to test for string-equality. As written you only test for the pointers being equal.

Instead use:

  • strcmp() for C-style strings
  • -isEqualToString: for NSString
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜