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?
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.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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.