我正在使用 Apple 指南中的这个非常简单的代码:
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 forbids explicit message send of 'retain'
如何处理?我正在使用 Xcode 4.4.1
最佳答案
您目前正在使用 ARC 为您引用计数。 (ARC 是“自动引用计数”,iOS 5 的一项新功能)。因此您不需要手动保留或释放。您可以通过执行以下操作一起删除保留调用或关闭 ARC:
单击左侧导航 View 中的项目名称,转到 Targets -> Build Phases 并将 -fno-objc-arc
添加到任何相关的“compiler flags”文件。
关于objective-c - ARC 禁止发送 'retain' 问题的显式消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11877025/