Created an empty project in Xcode, which merely sets up the App Delegate with a window object.
While AppDelegate.h creates a @property for window:
@property (strong, nonatomic) UIWindow *window;
There is no mention in either the .h or .m of the ivar _window however the dealloc shows:
- (void)dealloc
{
[_window release];
[super dealloc];
}
So my question is, does an @property automatically create an ivar with an underscore for the associate ivar for the property? I thought that unless you write something like @synthesize window=_window then properties and ivars have the same name. However there is no such (or any) @synthesize statement in the .m so where is the _window coming from?
LLVM 4.0, the default compiler for Xcode 4.4, provides a new feature called auto-synthesis that will automatically synthesize declared properties (unless they’re declared in a protocol). In addition to synthesizing getter and setter (if necessary) implementations, auto-synthesis will also synthesize an instance variable prefixed with an underscore. So given the following declaration…
…the compiler will synthesize an instance variable named
_fooas well asfooandsetFoo:method implementations that access_foo.