arachide
arachide

Reputation: 8066

AppDelegate Access

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

Upvotes: 5

Views: 5744

Answers (3)

rohan-patel
rohan-patel

Reputation: 5782

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.

Upvotes: 9

Michael Frederick
Michael Frederick

Reputation: 16714

You don't have to change anything for iOS 5. The UIResponder class inherits from NSObject.

Upvotes: 4

DivineDesert
DivineDesert

Reputation: 6954

Yes you can use the same thing you were using to access appDelegate..

Upvotes: 0

Related Questions