NOTE: i changed the names, i dont actually have a type letters.
in my root view controller .h, i do
typedef enum {
a,
b,
c,
d,
e }letters;
i have several other classes, most of which need to use this "letters" type. in my root view controller, i use "#import "MyClass.h" to import the class (since i make an instance of it in rootViewController). however, this does not allow MyClass to use the type "letters".
i tried adding in MyClass.h, "#import rootViewController.h", but xcode started giving me errors (only sometimes, it was on and off). what is the best way to do this? should i just import the rootViewController to all of the classes that need this "letters" type? is it ok to have both rootViewController importing MyClass and MyClass importing rootViewController?
If you need to use the enum only in connection with one class, go ahead and include it in that class's .h file. If you need to use the enum in many different places, you would probably be better served by creating a .h file just to declare the enum, and include that wherever you need it.
Your errors were probably coming from missing forward declarations. If RootViewController has ivars, properties, or method signatures that refer to MyClass, then there needs to be either a @class MyClass;
or an @interface block for MyClass visible before the compiler gets to those ivars, properties, or method signatures. If RootViewController.h and MyClass.h both include the other, then it will work if RootViewController.h is imported first but fail if MyClass.h is imported first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With