What I understand is that a protocol specify method names, and someone else who conforms to that protocol do the implementation of the methods.
So what about the properties declared in a protocol? Is that to implement a property means to implement its setter and getter?
Property is a fancy name for one or two methods with specific signatures for which Objective-C provides a convention that lets you call them using the alternative dot .
syntax. There is no difference between a protocol declaring, say, a pair of
-(int) foo;
-(void)setFoo:(int)_foo;
methods, and a protocol declaring a read-write property:
@property (readwrite) foo;
So you are absolutely right, implementing a property means implementing one or two methods, depending on whether you implement a read-only, write-only, or a read-write property.
As the others said, you just have to implements the getter and or setter (depending on the property).
I would add that you can just synthesize them :
@property (nonatomic, retain) NSObject * foo;
would end up in :
@synthesize foo;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With