views:

78

answers:

3

I have a large class, which I have divided into several different class extension files for readability.

@protocol MyProtocol
@required
-(void)required;
@end

@interface MyClass : NSObject <MyProtocol>
@end

@interface MyClass (RequiredExtension)
-(void)required;
@end

Is there a better way to do this, without the compiler warning?

 warning: class 'MyClass' does not fully implement the 'MyProtocol' protocol
+1  A: 

If that's only for readability, you should use categories only. A protocol is not needed in such a case.

Macmade
+2  A: 
@interface MyClass : NSObject
@end

@interface MyClass (RequiredExtension) <MyProtocol>
-(void)required;
@end

Adopt the protocol in the category.

KennyTM
+4  A: 

Use a category for each protocol implementation. I use this when I have complex viewControllers.

For example, I have a category that implements NSTextDelegate protocol.

So, MyComplexViewController+NSTextDelegate.h:

#import "MyComplexViewController.h"

@interface MyComplexViewController (NSTextDelegate) <NSTextDelegate>

@end

and MyComplexViewController+NSTextDelegate.m:

#import "MyComplexViewController+NSTextDelegate.h"

@implementation MyComplexViewController (NSTextDelegate)

- (BOOL)textShouldBeginEditing:(NSText *)textObject{
    ...
}

- (BOOL)textShouldEndEditing:(NSText *)textObject{
    ...
}

- (void)textDidBeginEditing:(NSNotification *)notification{
    ...
}

- (void)textDidEndEditing:(NSNotification *)notification{
    ...
}

- (void)textDidChange:(NSNotification *)notification{
    ....
}

@end

Then I take all the headers for the main class definition and the categories and combine them into one header which I then import where I need to use the class.

TechZen