NSAutoreleasePool 不可用
我正在关注“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
快速发布以防万一您仍在寻找
您可以在构建设置中禁用 ARC。
在用户定义设置下列为“CLANG_ENABLE_OBJC_ARC”
组),(如果您在构建设置下没有找到 ARC 选项,您可能需要
切换你的编译器。您可以在构建设置下找到它)
Quick post just in case you still looking
You can disable ARC in build settings.
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)
就我而言,我希望启用 ARC,并希望更新示例项目以使其正常工作。 Apple 的 NSAutoReleasePool 文档在技术上是正确的,但没有直接解释这一点。方法如下:
将您的应用程序设为 main,它可能看起来像这样:
并将其更改为如下所示:
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:
And change it to look like this:
这是 链接 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.
第一次创建新项目时会启用 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.
要求编译器在启用 ARC(自动引用计数)的情况下编译文件。关闭它,或者更好的是,使您的示例现代化:(
不,我无法具体告诉您如何关闭 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:
(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.)