You can do it, but be careful with how you import headers. This is the recommended way:
AppDelegate.h:
// Import headers here
@class MyViewController;
@interface AppDelegate : NSObject <UIApplicationDelegate> {
MyViewController *viewController;
}
- (void)someMethod;
@end
AppDelegate.m:
#import "AppDelegate.h"
#import "MyViewController.h"
@implementation AppDelegate
//Your code here
@end
MyViewController.h:
// Import headers here
@class AppDelegate;
@interface MyViewController : UIViewController {
AppDelegate *appDelegate;
}
@end
MyViewController.m:
#import "MyViewController.h"
#import "AppDelegate.h"
@implementation MyViewController
// Your code here
@end
As you can see, you want to use @class
to declare the classes in your headers, and then import the header in your .m
files. This ensures that you’re not importing things that you don’t need; if you imported the view controller header in your app delegate’s header, it would be imported into anything that imported your app delegate’s header. By leaving all the imports to the .m
files, you prevent that situation.