ios “接收者类型‘CALayer’例如消息是前向声明”在这里是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7813379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:55:38  来源:igfitidea点击:

What does "Receiver type 'CALayer' for instance message is a forward declaration" mean here?

objective-cioscore-animationcalayerautomatic-ref-counting

提问by Jason George

I'm porting a block of code from an iOS4 project to iOS5 and I'm having some troubles with ARC. The code generates a PDF from a screen capture.

我正在将一段代码从 iOS4 项目移植到 iOS5,但我在使用 ARC 时遇到了一些麻烦。该代码从屏幕截图生成 PDF。

PDF Generation Code

PDF生成代码

UIView *captureView;
...
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, captureView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[captureView.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();

The renderInContext line

renderInContext 行

[captureView.layer renderInContext:pdfContext];

generates the following error.

产生以下错误。

Automatic Reference Counting issue
Receiver type 'CALayer' for instance message is a forward declaration

Any ideas what is going on here?

任何想法这里发生了什么?

回答by NJones

I was able to duplicate your problem. This is what fixed it for me.

我能够复制你的问题。这就是为我修复它的原因。

Add QuartzCore.framework to your project and this line to your .m file.

将 QuartzCore.framework 添加到您的项目中,并将这一行添加到您的 .m 文件中。

#import <QuartzCore/QuartzCore.h>