I have an object which implements various protocols (like 10 different ones).
For example
@interface MyClass <UITableViewDelegate,UITableViewDataSource,UISearchDisplayDelegate,...>
@end
@implementation
/// a whole bunch of methods for the delegates
@end
In order to "clean" things up in this class - I have created helper classes which encapsulates the logic pertaining to those delegates.
so now the new refactored class looks something like
// public interface which looks the same
@interface MyClass <UITableViewDelegate,UITableViewDataSource,UISearchDisplayDelegate,...>
@end
// private interface
@interface MyClass ()
// a bunch of objects which implement those methods
@property (nonatomic,strong) MyUITableviewDelegate *tableViewDelegate;
@property (nonatomic,strong) MyUITableviewDataSource *tableViewDelegate;
@property (nonatomic,strong) MySearchDisplayDelegate *searchDisplayDelegate;
// another bunch of objects which answer to the delegates
@end
@implementation
// all the delegate methods were moved out of here to the class which implements the method
@end
Now when an object of "MyClass
" is assigned as a delegate - it should return the runtime object which "answers" to those delegates (for instance if "MyClass
" object is assigned as a UITableViewDelegate
- the MyUITableviewDelegate
should be assigned.
How can this be done?
Must I override the forwardInvocation
in the "MyClass
" object?