ARC 禁止“保留"问题的显式消息发送 [英] ARC forbids explicit message send of 'retain' issue
问题描述
我正在使用 Apple 指南中的这个非常简单的代码:
I'm using this very simple code from the Apple Guide:
NSMutableData *receivedData;
// Create the request.
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [[NSMutableData data] retain];
} else {
// Inform the user that the connection failed.
}
但是对于行 receivedData = [[NSMutableData data] retain];
Xcode 给了我一个错误:PushController.m:72:25: ARC 禁止显式消息发送 'retain'
But for the line receivedData = [[NSMutableData data] retain];
Xcode gives me an error: PushController.m:72:25: ARC forbids explicit message send of 'retain'
如何处理?我正在使用 Xcode 4.4.1
How to deal with it? I'm using the Xcode 4.4.1
推荐答案
您当前正在使用 ARC 为您引用计数.(ARC 是自动引用计数",iOS 5 的一项新功能).因此您无需手动保留或释放.您可以通过执行以下操作一起删除所有保留调用或关闭 ARC:
You are currently using the ARC to reference count for you. (ARC is "Automatic Reference Counting", a new feature to iOS 5). Therefore you do not need to manually retain or release. You can either remove your retain calls all together or turn off ARC by doing the following:
在左侧导航视图中单击项目名称,转到 Targets -> Build Phases 并将 -fno-objc-arc
添加到任何相关的编译器标志"文件.
Click on the name of the project on the navigation view in the left side, go to Targets -> Build Phases and add -fno-objc-arc
to the "compiler flags" for any relevant files.
这篇关于ARC 禁止“保留"问题的显式消息发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!