UIImageJPEGRepresentation上的ARC错误

Jef*_*ter 2 objective-c nsdata

一直在争夺这一个.基本上,我正在将图像转换为NSData,因此我可以将其发送到服务器.我之前使用过的代码,但由于某种原因,我在此处收到ARC错误.错误落在我声明imageData变量的行上.

注意:myImage将传递给该方法.

- (void)uploadImage:(NSImage *)myImage {

     NSData *imageData = UIImageJPEGRepresentation(myImage, 1.0);

     // Do something...

}
Run Code Online (Sandbox Code Playgroud)

我收到错误和两个警告

Error: Implicit conversion of 'int' to 'NSData *' is disallowed with ARC
Warning: Implicit declaration of function 'UIImageJPEGRepresentation' is invalid in C99
Warning: Incompatible integer to pointer conversion intializing 'NSData * __strong' with an expression of type 'int'
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Mar*_*tos 6

您可能需要包含相关标头:

#import <UIKit/UIKit.h>
Run Code Online (Sandbox Code Playgroud)

在C99之前,如果你调用编译器没有看到声明的函数,它将编译调用,就像声明函数一样int UIImageJPEGRepresentation().C99不允许这样,但似乎编译器仍在应用旧解释(或编译器处于C99之前的模式;我不确定默认值是什么),因此ARC错误.