I have been unable to find any information on this topic and most of what I know about it has come by complete accident (and a few hours of trying to figure out why my code
This may be an old question.. but in "modern times", @synthesize
- is NOT necessary.
@interface SomeClass : NSObject
@property NSString * autoIvar;
@end
@implementation SomeClass
- (id) init { return self = super.init ? _autoIvar = @"YAY!", self : nil; }
@end
The _underscored
backing ivar IS synthesized automatically... and is available within THIS class' implementation, directly (ie. without calling self
/ calling the automatically generated accessors).
You only need to synthesize it if you want to support subclass' ability to access the _backingIvar
(without calling self
), or for myriad other reasons, described elsewhere.