苹果是否声明我不知道的方法[CIImage initWithImage:(CIImage*)]
?我知道的签名的唯一方法是[CISampler initWithImage:]
。但是当我试图提供我自己的方法时,编译器警告我说该方法已经存在。隐藏[CIImage initWithImage:]方法?
背景:我试图创建一个便利的方法,将NSImage
实例转换为CIImage
。然后,我创建了一个类别方法[CIImage initWithImage:]
,它采用NSImage
实例。
这里是类方法声明:
@interface CIImage (QuartzCoreExtras)
-(id) initWithImage:(NSImage*) img;
@end
我试图用它在NSImageView
子类来缓存图像的CoreImage版本:
-(void) setImage:(NSImage *)newImage {
[super setImage:newImage];
[ciImage release];
ciImage = [[CIImage alloc] initWithImage:newImage];
}
但是,当我编译上面的方法,我收到一条警告,说别人已经定义了该方法,并采用不同的参数:
warning: incompatible Objective-C types 'struct NSImage *', expected 'struct CIImage *' when passing argument 1 of 'initWithImage:' from distinct Objective-C type
从XCode中的“跳转到定义”选项,该方法的唯一其他实现(除了我自己的实现)是[CISampler initWithImage:(CIImage*]
。我对这个问题感到很困惑 - 有什么我做错了吗?
只是为了完整起见,这里是[CIImage initWithImage:]
方法体:
@implementation CIImage (QuartzCoreExtras)
-(id) initWithImage:(NSImage*) img {
NSData* tiffData = [img TIFFRepresentation];
NSBitmapImageRep* bitmap = [NSBitmapImageRep imageRepWithData:tiffData];
return [self initWithBitmapImageRep:bitmap];
}
@end
在此先感谢。
如果提问者使用相同的选择器,那么Apple命名他们的方法并不重要,反之亦然 - 实际上,可能会有一个隐藏的' - [CIImage initWithImage:]'(或' initWithNSImage:'方法,这就是为什么标记任何您添加到类别中的方法的好方法,它的前缀或后缀对应用程序是唯一的。 – 2010-07-18 07:40:02
我确实包含了我的类别的头文件,并且仍然收到编译器警告。最终我放弃了,并命名我的方法“initWithNSImage”。 – adib 2010-07-20 04:03:18