基础 - 返回 NSMutableString

发布于 2024-11-27 04:59:30 字数 321 浏览 4 评论 0原文

我想在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ペ泪落弦音 2024-12-04 04:59:30

这是你的主要职能。正如您从声明 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 an int. In fact, main() is only allowed to return an int, 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 use NSLog(@"%@", result) or printf("%s", [result UTF8String]).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文