I switched to Xcode 4 recently and I don't really understand this new way to write accessors.
For example, in the application delegate class that is auto-generated when creating a new project, the window
object is not declared in the @interface
but just this way:
@property (nonatomic, retain) IBOutlet UIWindow *window;
Then, in the implementation file, we have the @synthesize window=_window;
.
And in the functions, we have either self.window
OR _window
.
For example:
[self.window makeKeyAndVisible]; // in didFinishLaunchingWithOptions function
[_window release]; // in dealloc function
Can you explain me the difference, why there is nothing in the @interface
, why we do @synthesize window=_window;
instead of @synthesize window;
and what is the difference between self.window
and _window
, I mean when do I have to call one more than the other?
I'm a bit lost, and feel like the new code I doing trying to do the same in not working properly...
Thanks!
The Information Property List ( Info.plist ) is a required iOS file that provides information about your application's configuration to the system.
Accessing the Accessibility InspectorChoose Accessibility in the Tools > Browser Tools menu. Select the Accessibility tab in the Developer Tools toolbox. Right-click in the main browser window, and choose Inspect Accessibility Properties in the context menu.
"Why is there nothing in the @interface
"
The runtime is synthesizing the ivar for you.
"Why do we do @synthesize window=_window;
This means that the window
property will use an ivar named _window
(by default the ivar name is the name of the property)
"What is the difference between self.window
and _window
?"
The former is using the window
"getter" method (ie, foo = [self window]
), and the latter is accessing the ivar directly.
"Why do I have to call one more than the other?"
It is generally considered unsafe to use accessor methods in your dealloc
method, which means using the ivar is preferred.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With