消息:预期标识符

时间:2012-06-28 07:25:34

标签: iphone objective-c

为什么会出现这个错误?我认为我关闭了所有括号。这是代码:

  int i=0;

    while(i<count){

    if([[ageMatch rangeOfString:age].location != NSNotFound] && [[glassesSex rangeOfString:gender].location !=NSNotFound] && [[faceMatch rangeOfString:shape].location != NSNotFound]  ){ //Expected identifier
            [arrayNuovo insertObject:dictionary atIndex:i];

        }
        i++;
     }

2 个答案:

答案 0 :(得分:2)

你应该改变

if([[ageMatch rangeOfString:age].location != NSNotFound] && [[glassesSex rangeOfString:gender].location !=NSNotFound] && [[faceMatch rangeOfString:shape].location != NSNotFound]  )

 if([ageMatch rangeOfString:age].location != NSNotFound && 
    [glassesSex rangeOfString:gender].location !=NSNotFound && 
    [faceMatch rangeOfString:shape].location != NSNotFound  )

当你进行布尔测试时,你会像[string rangeOfString:age].location != NSNotFound那样进行,并且不要将它们包括在[和]中

答案 1 :(得分:0)

使用此代码

while(i < count){
if(([ageMatch rangeOfString:age].location != NSNotFound) && ([glassesSex rangeOfString:gender].location !=NSNotFound) && ([faceMatch rangeOfString:shape].location != NSNotFound)  ){ //Expected identifier
        [arrayNuovo insertObject:dictionary atIndex:i];
            }
    i++;
}