Reputation: 955
I am making an SDK and i want something like @required for a variable. Something like delegate method with the @required annoation which make that method to conform mandatory. How can i achieve this thing in objective-c ..?
Upvotes: 0
Views: 35
Reputation: 11211
You may add a property declaration to a protocol, just as you would with any other method. As always with protocols, members are required by default.
If the required property is readwrite
(the default), then conforming classes must implement both the getter and the setter. They may do so manually or with compiler-provided implementations, as your needs dictate. Similarly, if the required property is readonly
, only the getter must be implemented, though of course you may implement the setter as well.
@protocol SerialNumbered <NSObject>
@property (strong, nonatomic, readonly) NSString *serialNumber;
@end
Upvotes: 1