相关疑难解决方法(0)

如何为项目中的单个文件禁用ARC?

我在我的项目中成功使用ARC.但是,我遇到了一些文件(例如,在单元测试和模拟对象中),其中ARC的规则现在更加脆弱.我记得听说有一种方法可以在每个文件的基础上禁用ARC,但我无法找到这个选项.

这可能吗?如何基于每个文件禁用ARC?

xcode objective-c automatic-ref-counting manual-retain-release

1332
推荐指数
14
解决办法
33万
查看次数

ARC禁止明确发送"保留"问题的消息

我正在使用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.
}
Run Code Online (Sandbox Code Playgroud)

但是对于receivedData = [[NSMutableData data] retain];Xcode 行我给出了一个错误:PushController.m:72:25: ARC forbids explicit …

xcode cocoa memory-management objective-c automatic-ref-counting

12
推荐指数
1
解决办法
3万
查看次数