How can you use circular #import to strongly typed objects in objective-c
I have an audio controller class, a menu class and a gameview class.
The application delegate sets up these classes and assigns a pointers so:
the menu class is aware of the audio and gameview class
the gameview class has a reference to the audio and menu class
I am using NSObject for the reference to the gameview class from the menu class. This is because the menu class has a reference to the gameview class and has a #import gameview.h declaration. The code won’t compile with circular #import
Suggestions please 🙂 ?
@interface MenuViewController : UIViewController {
NSObject *gameref; // weak type here to avoid include of gameview above
AudioController *audioref;
}
and…
#import "AudioController.h"
#import "MenuViewController.h"
@interface GameViewController : UIViewController {
MenuViewController *menuref;
AudioController *audioref;
}
Fisrt, in your .h file use
and
in your .m file use
and
There is no ‘circular reference’ problem.
Second, using NSObject instead of the actual classname isn’t in any way a weak reference. Also, if you mean #include say #include. If you mean #import, say #import.