'int'到'NSString*'的隐式转换


//This is to give a general idea of what is being called
int realQuestionIndex;
realQuestionIndex = currentQuestionIndex;
currentQuestionIndex = 0;
//The below code is where I'm receiving the error
questionIndexLabel.text = NSStringf(@"%d", realQuestionIndex+1);
//The updated code with NSString stringWithFormat producing error
questionIndexLabel.text = [NSString stringWithFormat:(@"%d",realQuestionIndex+1)];

我正在修复别人项目中的错误,但我以前从未使用过 NSStringf。 我被建议使用NSString stringWithFormat。但我仍然收到相同的错误。 有什么想法吗? 对不起,新手问题!

我猜NSStringf((是一个预处理器宏,#defined 这些文件包含的某个头文件中。它可能只是创建对stringWithFormat的调用。

这是毫无意义和丑陋的。只需使用普通的 stringWithFormat 语法,正如其他人已经在注释中解释的那样:

questionIndexLabel.text = [NSString stringWithFormat:@"%d",realQuestionIndex+1];

(不带括号(

@LyndseyScott,您应该将您的评论作为答案发布,以便 OP 可以接受它并获得荣誉。

最新更新