gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 12:26:45 25 4
gpt4 key购买 nike

//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 可以接受它并获得荣誉。

关于ios - 'int' 到 'NSString*' 的隐式转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28866655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com