Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWIndow Not Declared iOS 4.3 AppDelegate

I just downloaded the newest iOS SDK (4.3) and noticed that when I start a Window Based Application, the UIWindow is not declared in the header file, it is only mentioned as a property.

#import <UIKit/UIKit.h>

@interface GleekAppDelegate : NSObject <UIApplicationDelegate> {
    IBOutlet UILabel *label;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

I would expect, and remember from older SDK's, that the above code should be

#import <UIKit/UIKit.h>

@interface GleekAppDelegate : NSObject <UIApplicationDelegate> {
    IBOutlet UILabel *label;

    UIWindow *window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

Is that just a new feature of the SDK?

Thanks

like image 510
Tyler DeWitt Avatar asked Feb 12 '26 05:02

Tyler DeWitt


1 Answers

The new Objective-C runtime has the ability to synthesize ivars without explicitly declaring them. From Runtime Difference in The Objective-C Programming Language:

In general the behavior of properties is identical on both modern and legacy runtimes (see “Runtime Versions and Platforms” in Objective-C Runtime Programming Guide). There is one key difference: the modern runtime supports instance variable synthesis whereas the legacy runtime does not.

...

With the modern runtime, if you do not provide an instance variable, the compiler adds one for you.

From Runtime Versions and Platforms in Objective-C Runtime Programming Guide:

  • Phone applications and 64-bit programs on Mac OS X v10.5 and later use the modern version of the runtime.

  • Other programs (32-bit programs on Mac OS X desktop) use the legacy version of the runtime.

Also have a look at this questions:

  • Objective C: Why do we declare ivars in the .h member area if @property seems to do it automatically?

  • What is the underlying mechanism for ivar synthesis in the modern Objective C runtime

  • Automatic iVars with @synthesize

like image 93
albertamg Avatar answered Feb 14 '26 17:02

albertamg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!