Thursday 4 June 2015

Protocol Inheritance

Like classes and controllers, protocols itself can also be extended and can be used to produce new protocols.
Here we are creating a base Protocol with superset methods.
We can also call it original protocol. it is inherited from NSObject, like other classes in C.
  1. @protocol BaseProtocolDelegate <NSObject>
  2. - (void)testProtocol;
  3. @end
  4. @interface BaseViewController : UIViewController
Here we are creating a child Protocol inheriting Base protocol
  1. @protocol ChildProtocol <BaseProtocolDelegate>
  2. - (void)testChildProtocol;
  3. @end
  4. @interface FirstViewController : BaseViewController
  5. @property (nonatomic, retain)id <ChildProtocol> childProtocol;
we can call/use methods of protocols like:
  1. [childProtocol testProtocol];

For such more Blogs you can visit to http://findnerd.com/NerdDigest

No comments:

Post a Comment