Re:Show HN: My First iOS Game - Lumio
by LTheobald on Tuesday March 19, 2013 @07:57AM
(#5400317)
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.
[ Parent
| on HN ]
Read http://developer.apple.com/library/ios/#releasenotes/Objecti... and on a related note, read 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.
> 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.