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
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.
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.
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.
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