Search code examples
objective-cxcode4

What causes Category is implementing a method which will also be implemented by its primary class?


My other programmer download this code from the net

#import "UIImage+Alpha.h"

// Private helper methods
@interface UIImage ()
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size;
@end

@implementation UIImage (Alpha)

I got error: What causes Category is implementing a method which will also be implemented by its primary class?

I search for newBorderMask in my whole files and the word only show up 3 times.

It's only declared once namely on

@interface UIImage ()
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size;
@end

Implemented once namely in

#pragma mark -
#pragma mark Private helper methods

// Creates a mask that makes the outer edges transparent and everything else opaque
// The size must include the entire mask (opaque part + transparent border)
// The caller is responsible for releasing the returned reference by calling CGImageRelease
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size1 {
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();

and called once

 CGImageRef maskImageRef = [self newBorderMask:borderSize size:newRect.size];

So there is no double declaration.

So what's the problem.


Solution

  • I am the original author of the code, and Aadhira's answer is incorrect. The category name for this method should not be changed to "Alpha", as the method is intended to be private and not part of the extension.

    To get rid of the warning, the best workaround is to give the private category a unique name, such as "PrivateAlpha".

    For more details, see this discussion.