NSAutoreleasePool 不可用

发布于 2024-11-19 07:05:12 字数 549 浏览 2 评论 0原文

我正在关注“Objective-C 编程”第三版,但我在第一个示例中遇到了问题。

我不断收到此错误:

语义问题:“NSAutoreleasePool”不可用:不可用 自动引用计数模式

这是我的代码:

//
// main.m
// prog1 //
// Created by Steve Kochan on 1/30/11.
// Copyright 2011 ClassroomM, Inc.. All rights reserved. //

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSLog (@"Programming is fun!");
    [pool drain];
    return 0;
}

任何见解将不胜感激。

I am following "Programming in Objective-C" 3rd edition and I am having problems with the first example.

I keep getting this error:

Semantic Issue: 'NSAutoreleasePool' is unavailable: not available in
automatic reference counting mode

Here is my code:

//
// main.m
// prog1 //
// Created by Steve Kochan on 1/30/11.
// Copyright 2011 ClassroomM, Inc.. All rights reserved. //

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSLog (@"Programming is fun!");
    [pool drain];
    return 0;
}

Any insight will be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

长途伴 2024-11-26 07:05:13

快速发布以防万一您仍在寻找

您可以在构建设置中禁用 ARC。

  • 在左侧管理器中单击您的项目。
  • 选择你的目标,在下一栏结束。
  • 选择顶部的构建设置选项卡。
  • 向下滚动到“Objective-C 自动引用计数”(可能是
    用户定义设置下列为“CLANG_ENABLE_OBJC_ARC”
    组),(如果您在构建设置下没有找到 ARC 选项,您可能需要
    切换你的编译器。您可以在构建设置下找到它)
  • 并将其设置为“否”。

Quick post just in case you still looking

You can disable ARC in build settings.

  • Click on you project, in the left hand organizer.
  • Select your target, in the next column over.
  • Select the Build Settings tab at the top.
  • Scroll down to "Objective-C Automatic Reference Counting" (it may be
    listed as "CLANG_ENABLE_OBJC_ARC" under the User-Defined settings
    group), (if you do not find ARC option under build settings, you might need
    to toggle you compiler. You can find it under build settings)
  • and set it to NO.
很酷不放纵 2024-11-26 07:05:13

就我而言,我希望启用 ARC,并希望更新示例项目以使其正常工作。 Apple 的 NSAutoReleasePool 文档在技术上是正确的,但没有直接解释这一点。方法如下:

将您的应用程序设为 main,它可能看起来像这样:

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([DemoAppDelegate class]));

    [pool release];

    return retVal;
}

并将其更改为如下所示:

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([DemoAppDelegate class]));
    }
}

In my case, I wanted ARC on, and wanted to update a sample project to work properly. Apple's NSAutoReleasePool docs are technically correct, but don't come straight out and explain this. Here's how:

Take your application main, which probably looks something like this:

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([DemoAppDelegate class]));

    [pool release];

    return retVal;
}

And change it to look like this:

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([DemoAppDelegate class]));
    }
}
余厌 2024-11-26 07:05:13

这是 链接 Apple 的 ARC 过渡指南。

好的...检查 这个 出来。 NSAutoreleasePool 的具体更改 - 这是 Xcode 在创建第一个应用程序时初始化自身的方式。我不了解你,但我喜欢这个主意!

如果您正在阅读 Kochan 的书,请不用担心。启动项目时,只需取消选中“使用 ARC”框即可。一切都会成功。

Here is a link to Apple's transition guide to ARC.

OK...check this out. Specific change to NSAutoreleasePool - this is how Xcode initializes itself when you create your first app. I don't know about you, but I love this idea!

No worries if you are following along w/ Kochan's book. When starting your project, just uncheck the "Use ARC" box. Everything will work.

过气美图社 2024-11-26 07:05:13

第一次创建新项目时会启用 ARC。我知道如何启用或不启用它的唯一方法是在您第一次创建程序时。它是您必须取消选择的复选框之一。

ARC is enabled when you first create a new project. Right know the only way I know how to enable or not enable it is when you first create your program. It is one of the checkboxes you have to unselect.

执着的年纪 2024-11-26 07:05:12

要求编译器在启用 ARC(自动引用计数)的情况下编译文件。关闭它,或者更好的是,使您的示例现代化:(

int main (int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog (@"Programming is fun!");
    }
    return 0;
}

不,我无法具体告诉您如何关闭 ARC,如果这是您由于上述 NDA 而要走的路线。)

The compiler is being asked to compile the file with ARC (automatic reference counting) enabled. Turn that off or, better yet, modernize your example:

int main (int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog (@"Programming is fun!");
    }
    return 0;
}

(No, I can't tell you how, specifically, to turn off ARC, if that was the route you were to go down due to the aforementioned NDA.)

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