@protocol myProtocol
//@required
-(NSString *)requiredMethod:(MyCustomObject *)myObject;
@optional
-(NSString *)optionalMethod:(MyCustomObject *)myObject;
@end
respondsToSelector can be used to see if the optional method exists and if so, react to it.
@interface myClass : aSuperClass
...
if ([self.delegate respondsToSelector:@selector(optionalMethod:)]) {
myString = [self.delegate optionalMethod:self];
} else {
myString = @"Default Value";
}
No comments:
Post a Comment