Objective C stringWithFormat if语句

Dav*_*vid 4 if-statement objective-c stringwithformat stringwithstring

我对此很新 - 我正在尝试将NSString stringWithFormat与一些文本进行比较.它与stringWithString一起工作正常.我无法弄清楚为什么它不能与stringWithFormat一起使用?非常感谢任何人提供的任何帮助!

    NSString *theQuestion = [NSString stringWithFormat:@"The same thing"];
if (theQuestion == @"The same thing"){
        NSLog(@"stringWithFormat is the same as the given text");
    }else{
NSLog(@"stringWithFormat is NOT the same as the given text");
        NSLog(@"but theQuestion is:\"%@\"", theQuestion);
    }
Run Code Online (Sandbox Code Playgroud)

jbt*_*ule 5

==是一个参考相等.做一个字符串比较它必须是

if([theQuestion isEqualToString:@"The same thing"]){

}
Run Code Online (Sandbox Code Playgroud)