Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

@property and @synthesize

edited September 2012 in Learn Cocoa On The Mac
I'm following the 2nd edition and on page 96 of the (alpha) ebook it states that "Xcode has created @synthesize declarations for each of the outlets".

I'm using Xcode 4.5 and that's not what see. Xcode doesn't auto-add the @synthesize declarations. I only see the "stubbed out empty methods for each of the actions."

Did this change in Xcode 4.5?

Comments

  • Yes! Starting in Xcode 4.4 and 4.5, the @synthesize is now optional. If you don't use @synthesize for your properties, the compiler will do an implicit synthesize, automatically creating the accessors, along with an instance variable named the same as the property, but with an underscore prepended. Concretely, assuming that you have declared a @property named "thing", leaving out the @synthesize is identical to doing this:

    @synthesize thing = _thing;

    So now, you only need to use @synthesize if you want to use a specific instance variable name that is different from the default. Personally, I really like having the underscore-prefixed names for my instance variables since it makes them really stick out on the code, making it easier to see at any point whether I'm using an accessor or directly accessing the instance variable. So I usually skip the @synthesize these days, and use the default.
Sign In or Register to comment.