In Java, there is wrapper classes. but in objective c what is there any wrapper class or something else?
In ObjectiveC protocol methods can be marked as @optional - those ones don't have to be implemented. e.g.
@protocol MyProtocol <NSObject>
@required
- (NSUInteger) methodOne;
@optional
- (NSUInteger) methodTwo; // Doesn't have to be implemented
@end
The method that calls the protocol should then check to see if the instance responds to that selector:
if ([anInstanceOfAClassThatImplementsMyProtocol respondsToSelector:@selector( )]) {
[myProtocolInstance methodTwo];
}
You wil get a warning if you dont implement obligatory methods in the protocol. A protocol is typically defined like this:
@protocol SomeProtocol<NSObject>
- (void)obligatoryMethod;
@optional
- (void)optionalMethod;
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With