簡體   English   中英

為什么我看到有關NSAutoreleasePool不可用的消息警告?

[英]Why am I seeing a message warning about NSAutoreleasePool being unavailable?

知道為什么我收到這些消息:

NSAutoreleasePool不可用:在自動引用計數模式下不可用

ARC禁止“發布”的顯式消息發送

在這段代碼中:

#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;
}

這是因為您正在使用自動引用計數進行編譯。 您需要在ARC中使用不同的構造:

@autoreleasepool {
    // Your code
}

另一個選項是為特定文件關閉ARC

是的,您啟用了自動引用計數,這不允許您明確使用'release'。 您需要禁用ARC或將主方法更改為如下所示:

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

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM