views:

75

answers:

2

In my iPhone apps I regularly do this in xCode v3.2.3:

  1. Declare a BOOL variable in the *.h file
  2. Use @property in the same *.h file.
  3. Use @sythesize in the matching *.m file.

I accidentally forgot to do #1... but it still complied fine. 0 warnings. 0 errors. 0 analyzer errors.

How can that be? Shouldn't my code to loaded with compiler-errors everywhere that variable is trying to be used?

+5  A: 

This is a feature of the new runtime. See this question for more details.

e.James
Thanks for the fast reply. Is there a way for me to FORCE a warning/error for those types of issues? (I DO want to see them.)
Annette
Why do you want to see them? The compiler is creating them for you.
Jeff Kelley
@Annette - As Jeff said, there is no need for a warning, because there is nothing at all wrong with not declaring the instance variable for a property in the modern runtime.
Brad Larson
+2  A: 

Automatic synthesis of instance variables (ivars) is a feature of the Objective-C 2.0 runtime on OS X and of the new iOS Objective-C runtime. The @synthesize directive will automatically create the necessary ivar at runtime unless you have declared it yourself. This is made possible by Objective-C 2.0's non-fragile ivar support. Thus, there is no error and you should not receive them.

Ultimately, it's a good thing that you don't have to declare ivars in the interface of a class. They are (probably) implementation-specific details which you don't want to have visible as part of the public interface of the class. Note that using class categories you can also automatically synthesize ivars for "private" properties as well.

Barry Wark