Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 506
user4951 Avatar asked Apr 18 '12 03:04

user4951


3 Answers

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.

like image 169
vocaro Avatar answered Nov 10 '22 20:11

vocaro


See, while you declare the category, it is like

@interface UIImage ()

But in implementation, it is like

@implementation UIImage (Alpha)

So declare it as follows:

@interface UIImage (Alpha)
like image 35
Ilanchezhian Avatar answered Nov 10 '22 22:11

Ilanchezhian


I just removed this whole bit from my .m file:

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

LLVM 4.1 compiler doesn't seem to care about it anymore.

like image 24
Jay Q. Avatar answered Nov 10 '22 22:11

Jay Q.