Elegant global access to App Delegate
I know, I know… accessing the app delegate globally is not always a good idea but sometimes it's just the right thing to do. This is an easy and elegant way to access it from any file in our project:
AppDelegate.h
#import <UIKit/UIKit.h>
#define ApplicationDelegate ((MyAppDelegate *)[UIApplication sharedApplication].delegate)
@interface MyAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (copy, nonatomic) NSString* aString;
@end
Any other file on the project
NSString* myString = ApplicationDelegate.aString;
Written by Sendoa Portuondo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#