首页 > 解决方案 > Set up interface definitions for a category, if methods of the category are called from another class

问题描述

Let’s say I have a class Alpha , and a category Alpha+morefeatures with a method -(void)foo. Another class , say Beta, should call the method foo.

I like to use the categories for splitting the code into parts, so that Alpha.m will not be a big file.Where should I put the includes & interface description then?

I tried:

file Alpha.h——————————</p>

@interface Alpha {
...
}

-(void) foo;

file Alpha.m——————————</p>

#import „Alpha.h“

file Alpha+morefeatures.h --------------

#import "Beta.h"

@interface Alpha (morefeatures)

file Alpha+morefeatures.m --------------

#import Alpha+morefeatures.h

@implementation Alpha (morefeatures)

-(void)foo {
...
}

file Beta.h——————————-

#import „Alpha.h“

Alpha+morefeatures.h is not imported anywhere else than in Alpha+morefeatures.m . This compiles ( and runs well) but it gives the following compiler warnings:

“Category is implementing a method which will also be implemented by its primary class”</p>

"Method definition not found"

How can I get rid of the warnings ? I have seen some answers which deal with compiler options - but I assume it is more a syntax problem.

Any advise is appreciated.

标签: objective-cxcodecategories

解决方案


我终于找到了一个办法:我所要做的就是将接口描述添加到Alpha.h中

@interface Alpha (morefeatures)  
  -(void)foo; 
@end

然后在 Beta.h 中导入Alpha.h


推荐阅读