I'm creating an Objective-C category on the UIViewController class. In my project, I want one singular and easy way to get the app delegate.
Here's what I'm doing
// header file UIViewController+AppDelgate.h
#import <UIKit/UIKit.h>
@class ExampleAppDelegate;
@interface UIViewController (AppDelegate)
@property (weak, nonatomic, readonly) ExampleAppDelegate *appDelegate;
@end
// implementation file UIViewController+AppDelegate.m
#import "UIViewController+AppDelegate.h"
#import "ExampleAppDelegate.h"
@implementation UIViewController (AppDelegate)
- (ExampleAppDelegate *) appDelegate {
return (ExampleAppDelegate *)[[UIApplication sharedApplication] delegate];
}
@end
Should I define the property as weak? I think it would be bad to retain this guy as it would normally have retains on view controllers referenced within.