AppDelegate Access

iphone

Solution

I do not know what misconception you have in your mind. But What I use in iOS 5 application development is still same.

As per your comment above you said you wrote this code:

#import "AppDelegate.h"
@property (nonatomic,retain) AppDelegate *appDelegate;  // This line is unnecessary

You do not have to create property for AppDelegate class's object. Just include this line in your .m file where you want to access global variable:

// Create an AppDelegate variable in your MapViewScreen @interface
AppDelegate *appDelegate;

#import "AppDelegate.h"
@implementation MapViewScreen

- (void)viewDidLoad  
{
    appDelegate = [[UIApplication sharedApplication] delegate];
}

P.S.: As Michael pointed out UIResponder inherits from NSObject so you do not have to worry. Everything's the same.

Problem

For the old version xcode/ios, I used: ``` appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate]; ``` to access AppDelegate ``` #import "AppDelegate.h" @property (nonatomic,retain) AppDelegate *appDelegate; #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> { } @property (strong, nonatomic) UIWindow *window; @end //----- #import <UIKit/UIKit.h> #import "AppDelegate.h" @interface DetailController : UIViewController{ } @property (nonatomic,retain) AppDelegate *appDelegate; @end ``` but in ios5 AppDelegate change from NSObject to UIRepsonder Is it possible to access the AppDelegate? Welcome ant comment

Original source