In the Modern Objective-C runtime, you can do something like this:
@interface MyClass : NSObject {
}
@property NSString *stringProperty;
@end
@implementation MyClass
@synthesize stringProperty;
@end
It is my understanding with the modern runtime this will not only synthesize the accessors for my property, but also the instance variable itself, so I could then say in one of this class's methods [stringProperty length];
and it would work just as if I'd declared an instance variable.
I've started using this in all my code now, because, well it's one less thing I have to write over and over again. And I've heard with the clang 2.0 compiler, I'll even be able to skip the @synthesize
(but that's another matter). But I've been wondering, what are some of the downsides to doing this? When might I truly need an instance variable in addition to my properties?
I know there are sometimes when I want to keep a variable private and not give access to it externally (but then I usually just declare the property in my private class extension, or I don't create a property for it at all, if I don't need accessors for it).
Are there any times when I wouldn't want to do this?