---
title: "Main difference between @Optional and @required keywords."  
description: "Main difference between @Optional and @required keywords."  
author: "Tarun Kumar"  
published: 2015-10-03  
updated: 2020-09-22  
canonical: https://www.mindstick.com/interview/22851/main-difference-between-optional-and-required-keywords  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Main difference between @Optional and @required keywords.

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  @optional  -(void) optional_method_name;  @required  -(void) required_method_name;@end
```

## Answers

### Answer by Tarun Kumar

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  @optional  -(void) optional_method_name;  @required  -(void) required_method_name;@end
```


---

Original Source: https://www.mindstick.com/interview/22851/main-difference-between-optional-and-required-keywords

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
