Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppDelegate Access

Tags:

iphone

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

like image 280
arachide Avatar asked Apr 07 '12 04:04

arachide


People also ask

What is use of AppDelegate in Swift?

Overview. Your app delegate object manages your app's shared behaviors. The app delegate is effectively the root object of your app, and it works in conjunction with UIApplication to manage some interactions with the system.

What is difference between AppDelegate and scene delegate?

AppDelegate is responsible for handling application-level events, like app launch and the SceneDelegate is responsible for scene lifecycle events like scene creation, destruction and state restoration of a UISceneSession.


1 Answers

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.

like image 174
rohan-patel Avatar answered Oct 06 '22 00:10

rohan-patel