Search code examples
objective-c-category

How do you import a category defined within it's parent class in objective-c?


I have a category following the format below, designed to encapsulate simplistic methods only necessary because they will be changed by children classes. How do I import this category into other classes, such as ClassOneTests.m, ClassOneA.h, .m and ClassOneB.h, .m? #import "ClassOne+MyCategory.h" gives an error.

ClassOne.m

#import "ClassOne.h"

@interface ClassOne ()
-(void)MethodOne
@end

@interface ClassOne (MyCategory)
-(NSString *)servantToMethodOne
@end

@implementation ClassOne
-(void)MethodOne {
[self servantToMethodOne];
...
}
@end

@implementation ClassOne (MyCategory)
...
@end

Solution

  • The solution is to separate the category interface into ClassOne.h and leave the imports as they are.