【问题标题】:Why am I seeing a message warning about NSAutoreleasePool being unavailable?为什么我会看到有关 NSAutoreleasePool 不可用的消息警告?
【发布时间】:2012-01-14 16:59:09
【问题描述】:

知道为什么我会收到这些消息:

NSAutoreleasePool 不可用:在自动引用中不可用 计数模式

ARC 禁止发送“release”的显式消息

在这段代码中:

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

【问题讨论】:

标签: iphone ios xcode


【解决方案1】:

这是因为您在编译时启用了自动引用计数。您需要对 ARC 使用不同的构造:

@autoreleasepool {
    // Your code
}

另一个选项是turn off ARC for a specific file

【讨论】:

    【解决方案2】:

    是的,您启用了自动引用计数,这不允许您显式使用“发布”。您需要禁用 ARC 或将 main 方法更改为如下所示:

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

    【讨论】:

      【解决方案3】:

      在targets->Build settings->Apple LLVM Complailer 3.0下

      Objective-C 垃圾回收(更改为 )支持 [-fobjc-gc]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-19
        相关资源
        最近更新 更多