Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the new Apple LLVM 4.0 "default synthesize" feature operate?

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.

like image 639
booker Avatar asked Feb 20 '23 17:02

booker


2 Answers

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).

like image 89
Kaan Dedeoglu Avatar answered Apr 29 '23 15:04

Kaan Dedeoglu


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.

like image 33
Dan Rosenstark Avatar answered Apr 29 '23 15:04

Dan Rosenstark