7 ms·
Got any references for this so I can do some further reading? As someone starting to learn Objective C, I'm mainly being told to use @synthesize. I did a quick
by LTheobald 14y ago
Got any references for this so I can do some further reading? As someone starting to learn Objective C, I'm mainly being told to use @synthesize. I did a quick Google for links about it not being required. There are some saying it might possibly be automatically added but then there were also a lot of responses saying this is still not the case & that @synthesize should be used still.
- hboon 14y agoRead http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/ObjCAvailabilityIndex/index.html http://developer.apple.com/library/ios/#releasenotes/Objecti... and on a related note, read http://clang.llvm.org/docs/ObjectiveCLiterals.html http://clang.llvm.org/docs/ObjectiveCLiterals.html too. You only need to synthesize when you access the variable directly. I always access via properties unless I'm within a setter for that property or if I want to bypass my own lazy loading getter code. So I'm left with only a few occasional @synthesize statements in most classes. And in Xcode, run Edit > Refactor > Convert to Modern Objective-C Syntax. I don't think it helps remove unnecessary @synthesize, but it sure helps with those super-double-extra-verbose-old-style container subscripting accesses.
- rimantas 14y ago> You only need to synthesize when you access the variable > directly. You don't. @property will take care about creating ivars. So with @property (strong, nonatomic) NSString *foo you get _foo and accessors. The only place I need @synthesize is in NSManagedObject subclasses.
- hboon 14y agoAh. I stand corrected. I @synthesize because I always want foo and not _foo.