Home > DeveloperSection > Interviews > Main difference between @Optional and @required keywords.

Posted on    October-03-2015 12:11 AM

 iPhone iPhone  Ios  Objective C 
 1 Answer(s)
  978  View(s)
Rate this:

Tarun Kumar

Total Post:107

Posted on    October-03-2015 12:11 AM

Protocol methods can be marked as optional using the @optional keyword. Corresponding to the @optional modal keyword, there is a @required keyword to formally denote the semantics of the default behavior. You can use @optional and @required to partition your protocol into sections as you see fit. If you do not specify any keyword, the default is @required, or you can say that the @optional directive applies to any methods that follow it, either until the end of the protocol definition, or until another directive is encountered, such as @required.
For example:

@protocol MyProtocol
  -(void) optional_method_name;
  -(void) required_method_name;

Don't want to miss updates? Please click the below button!

Follow MindStick