How does the new Apple LLVM 4.0 default synthesize feature work?

I read the release notes for Xcode 4.4 and noticed this:

LLVM 4.0 compiler

Xcode now includes the Apple LLVM 4.0 compiler, including the following newObjective-C functions:

  • Default @synthesize: automatically synthesizes @property when not implemented

I am intrigued by this feature. How it works? I tried to remove @synthesize , it does not work.

+4
source share
2 answers

It really works, make sure that in your project and target settings the compiler is installed in LLVM 4.0. Then, when you delete the @synthesize line, you can access it in two ways:

through an accessory with self.myProperty or through the corresponding instance variable using _myProperty (yes, the stands are added automatically).

+7
source

There are many cases where it simply does not work. All of them are described here as exceptions:

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

but the most important, for me, is called

Readwrite property with idle Getter and Setter

This means that if your properties are not public ivars, you need to enable @synthesize. Or, to put it another way, if you make good use of encapsulation and populate these setters and getters, you cannot use this.

Later Note: I am not sure about the conditions indicated here, but I found that there is an auto-synthesized ivar for almost every situation I encounter.

+1
source

All Articles