Creating our own optional methods in protocol

Total Post:6

 1091  View(s)
Rate this:
I have notice that optional methods in several protocols are defined in the iPhone SDK, such as the UIActionSheetDelegate protocol.
So my problem is that can I define a protocol of my own, and set a few of the methods as optional?
  1. Post:214

    Re: Creating our own optional methods in protocol

    When we create a Protocol then we need to mark '@optional' keyword, because it is responsible to create our own optional method.
    Corresponding to the '@optional' keyword, here is another keyword @required, used when we want any method necessary in our code, using @optional and @required keywords we can do partition in protocol into sections and by the way by default keyword is @required in any protocol.

    @protocol ProtocolSample

    - (void)defaultRequiredMethod;

      - (void)optionalMethod1;
      - (void)optionalMethod2;

      - (void)requiredMethod;




Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.