基础 - 返回 NSMutableString
我想在我的 Foundation 程序中返回一个 NSMutableString 。但是,我收到以下错误:
警告:语义问题:整数转换的指针不兼容 从结果类型为“int”的函数返回“NSMutableString *”
对于以下代码,
int main (int argc, const char * argv[])
{
NSMutableString* result = @"testing";
[pool drain];
return result;
}
I want to return an NSMutableString in my Foundation program. However, I get the following error:
warning: Semantic Issue: Incompatible pointer to integer conversion
returning 'NSMutableString *' from a function with result type 'int'
for the following code:
int main (int argc, const char * argv[])
{
NSMutableString* result = @"testing";
[pool drain];
return result;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是你的主要职能。正如您从声明
int main()
中看到的,它返回一个int
。事实上,main()
只允许返回一个int
,它表示失败或成功(一般0表示成功,任何其他数字是程序特定的错误代码) 。你不能在那里返回任何其他东西——它只是语言的一部分。如果您尝试打印字符串,可以使用NSLog(@"%@", result)
或printf("%s", [result UTF8String])
。That's your main function. As you can see from the declaration
int main()
, it returns anint
. In fact,main()
is only allowed to return anint
, which indicates failure or success (generally 0 means success and any other number is a program-specific error code). You can't return anything else there — it's just part of the language. If you're trying to print the string, you can useNSLog(@"%@", result)
orprintf("%s", [result UTF8String])
.