for performance reasons:
does my code perform better if I implement a delegate protocol such that the delegate implements all unused methods as no-op stubs, like this?
@protocol FooDelegate <NSObject>
- (void) requiredFooThing;
@end
....
// a class which implements FooDelegate:
- (void) requiredFooThing { /* does nothing */ };
or is it better to just make the protocol methods optional and use reflection to see if the callee will respond?
@protocol FooDelegate <NSObject>
@optional
- (void) optionalFooThing;
@end
....
// runtime reflection
if([_delegate respondsToSelector:@selector(optionalFooThing)])
{
[_delegate optionalFooThing];
}
the question is, is the runtime reflection more expensive than sending a message?