4

I was going through the release notes for Xcode 4.4 and noticed this:

LLVM 4.0 Compiler

Xcode now includes the Apple LLVM Compiler version 4.0, including the following newObjective-C language features:

  • Default @synthesize: automatically synthesizes an @property when unimplemented

I'm intrigued about this feature. How does it work? I have tried by deleting the @synthesize, it doesn't work.

Community
  • 1
  • 1
booker
  • 1,256
  • 1
  • 12
  • 18

2 Answers2

7

It does work actually, make sure that in your project and target settings the Compiler is set to LLVM 4.0. Then when you delete the @synthesize line you can access it in two ways:

through the accessor with self.myProperty or through the respective instance variable with _myProperty (yeah the underbars are added automatically).

Kaan Dedeoglu
  • 14,765
  • 5
  • 40
  • 41
1

There are many cases where it simply doesn't work. These are all outlined as exceptions here:

http://useyourloaf.com/blog/2012/08/01/property-synthesis-with-xcode-4-dot-4.html

but the most important one, to me, is called

Readwrite Property With Non-Default Getter and Setter

This means that, unless your properties are just public-facing ivars, you need to include a @synthesize. Or to put it another way, if you're using encapsulation well and filling up those setters and getters, you cannot use this.

Later Note: I'm not sure about the conditions specified here, but I find that there is a autosynthesized ivar for just about every situation I encounter.

Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421