I'm new to objective-c and have been wondering what's the point of creating properties? I can just create a variable in the header? Why create a variable and a property with the same name?
A:
Easier memory management (for some), better design (for all). Properties make your public interface to the class concrete, and it defines what is weakly and what is strongly referenced.
Joshua Weinberg
2010-07-19 13:55:20
A:
As an addition to what Joshua have said: properties are KVC/KVO-compatible while variables are not, whole Cocoa stands on KVO. You can bind a property and to property, you can add an observer, you can use valueForKey/valueForKeyPath and their 'set' brothers for free. If the value must be published (i.e. available for external classes) - make a property, you will get a lot of stuff for free. Just make sure you've set the proper memory management option (assign, copy or retain) and thread-safety modifier (nonatomic).
Gobra
2010-07-19 15:03:11