views:

43

answers:

1

Hello again. I have the following category:

@interface UIViewController (Additions)

- (void)exampleMethod;

@end

-----

#import "UIViewController+Additions.h"

@implementation UIViewController (Additions)

- (void)exampleMethod {
    NSLog(@"Example.");
}

@end

I also have the following abstract class:

@interface DFAbstractViewController : UIViewController

@end

-----

#import "DFAbstractViewController.h"
#import "UIViewController+Additions.h"

@implementation DFAbstractViewController

@end

And here's the concrete class:

#import "DFAbstractViewController.h"

@interface DFConcreteViewController : DFAbstractViewController

@end

-----

#import "DFConcreteViewController.h"

@implementation DFConcreteViewController

- (void)viewDidLoad {
    [self exampleMethod];
}

@end

Okay. So it's my understanding that the concrete class, DFConcreteViewController, can use methods imported from a category in its superclass, DFAbstractViewController. This is correct, because the method call works as expected.

The problem is Xcode is giving me the following warning: 'DFConcreteViewController' may not respond to '-exampleMethod'.

I don't see how this method and its availability to DFConcreteViewController isn't completely clear to the compiler? Perhaps I've misunderstood something about categories?

A: 

Right. I figured it out. It was an elementary mistake and one for which I feel rather foolish. If you want your category methods to be visible to subclasses, make sure to import your category in your header:

#import "UIViewController+Additions.h"

@interface DFAbstractViewController : UIViewController

@end
David Foster