ARC禁止显式消息发送'retain'问题 [英] ARC forbids explicit message send of 'retain' issue

查看:162
本文介绍了ARC禁止显式消息发送'retain'问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个非常简单的代码从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:

在左侧导航视图中单击项目名称,到目标 - >构建阶段,并将 -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上。

这篇关于ARC禁止显式消息发送'retain'问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆