I am currently learning about memory management and properties in Objective-C. I recently read through this post and answers to my previous question concerning how @property
and @synthesize
work in Objective-C. This has clarified things somewhat.
It seems like the point is to distinguish between local variables and member variables in terms of memory management, but I'm still not totally clear on the subject.
If I have:
@interface FooClass : NSObject {
NSObject *bar_;
}
why do I need to create the property? I mean, I understand that the property creates getters and setters, but so what? I have my instance variable bar_
which I can set using foo.bar_ = newObject;
. What advantages does it give me to have a property called bar
and then setting bar_
using foo.bar = newObject
?