Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors when making circular reference imports

My program was running fine, but I changed something and now it has over 48 errors.

I think I know the problem, but I don't know how to fix it. I created a class called mViewBase for all my UIViewControllers to derive from.

I decided to have a navigtion bar at the bottom of all my views, to go to other view controllers called cakes2. So cakes2.h imports mViewBase, and mViewBase import cakes2.h

You must be able to do this in Objective-C. Does anybody have any idea of what I can do?

My mViewBase.h file:

#import <UIKit/UIKit.h>
#import "Cakes2.h"

@interface mViewBase : UIViewController {
    UIView *mBackground;
    UIView *mBackArrow;
    UITextView *mTitle;
    //    Cakes2 *mCakes;
}

-(void) aSetTitle: (NSString *) NewTitle;
-(IBAction) aBack: (id) tender;
-(IBAction) aHome: (id) sender;
-(IBAction) aCakes: (id) sender;
-(IBAction) aCall: (id) sender;
-(IBAction) aDirections: (id) sender;
@end

My Cakes2.h file:

#import <UIKit/UIKit.h>
#import "Gallery.h"
#import "WebView.h"
#import "mViewBase.h" // Circular reference! But I need it

@interface Cakes2 : mViewBase <UITableViewDelegate, UITableViewDataSource> {
    //    Gallery *mGallery;
    IBOutlet UITableView *mMenu;
    // WebView *mWebView;
}
-(IBAction) aOpenWeb;
@end
like image 379
Ted pottel Avatar asked Aug 28 '11 13:08

Ted pottel


1 Answers

You can use a forward declaration in one of your header files to avoid the need to import the other header. For example, in mViewBase.h, you can say:

@class Cakes2;

Now the compiler knows that "Cakes2" refers to a class, and you don't need to import the entire Cakes2.h file.

like image 146
Caleb Avatar answered Oct 17 '22 17:10

Caleb