I’m developing an iPhone app, and I’m kinda new to Objective-C and also the class.h and class.m structure.
Now, I have two classes that both need to have a variable of the other one’s type. But it just seems impossible.
If in class1.m (or class2.m) I include class1.h, and then class2.h, I can’t declare class2 variables in class1.h, if I include class2.h and then class1.h, I can’t declare class1 variables in class2.h.
Hope you got my idea, because this is driving me nuts. Is it really impossible to accomplish this?
Thanks.
You can use the
@classkeyword to forward-declare a class in the header file. This lets you use the class name to define instance variables without having to#importthe header file.Class1.h
Class2.h
Note that you will still have to
#importthe appropriate header file in your .m files