I have two view controllers A and B, and they both have each other as their delegates.
When I did nothing except define the protocols at the beginning of the header files and #import the other's header file, I got two errors along the lines of -
cannot find protocol declaration for "BDelegate", which was showing in A.h (where I wrote ) cannot find protocol declaration for "ADelegate", which was showing in B.h (where I wrote )
Looking online, people had written earlier that the circular inclusion of header files could be leading to the problems. They recommended either using #include instead, or @class declaration like -
@class A instead of
#import A.h inside #import B.h
I have tried almost every combination of these imports, and @classes, and #include but still can't get rid of the warnings. Also, solutions online recommended moving the #import to the .m files but that didn't help either. Part of the reason is that the solutions online are kinda fuzzy - if you could break it down that would be great.
Any suggestions about what can be done to fix this?
-- BigViewController.h --
#import "BaseViewController.h" #include "BaseViewController.h" @class BigViewController; @protocol BigViewControllerDelegate -(void) BigViewController:(BigViewController *) bigView; @end @interface BigViewController : UIViewController <BaseViewControllerDelegate> { //delegate id <BigViewControllerDelegate> delegate; ivars... } @properties... @end -------------------------------------------------- -- BaseViewController.h --
#<UIKit/UIKit.h> #import "BigViewController.h" #include "BigViewController.h" @class BigViewController; @protocol BaseViewControllerDelegate - (void) setParametersWithItemChosen:(Item *) item; @end @interface BaseViewController : UIViewController <...BigViewControllerDelegate...> { ivars... //delegate id <BaseViewControllerDelegate> delegate; } @properties... @end
{}button at the top to encase the code, or else manually format it using back tick.