How can I have references between two classes in Objective-C?


How can I have references between two classes in Objective-C?



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.


mobile_fu rendering over AJAX so it seems

1:

iphone nslog corrupted data
You must use the @class keyword to forward-declare a class in the header file. Use a C++ file in Cocoa iPhone AppThis lets you use the class name to define instance variables without having to #import the header file.. Where to find a description of all the math functions like floorf and others? Class1.h. How to take these parameters the same way this function does?
@class Class2;  @interface Class1 {     Class2 * class2_instance; } ... error: property 'myBoolVariableName' with 'retain' attribute must be of object type@end 
Class2.h. does javascript on iphone mobile safari support xpath?
@class Class1;  @interface Class2 {     Class1 * class1_instance; } ... Passing NSInteger variable to NSMutableDictionary or NSMutableArray@end 
Note this you will still have to #import the appropriate header file in your .m files.

2:

A circular dependency is often an indication of a design problem. Probably one or both of the classes have too many responsibilities. A refactoring this must emerge from a circular dependency is moving the interdependent functionality into its own class this the two original classes both consume.. Can you describe the functionality this each class requires from the other?.


90 out of 100 based on 35 user ratings 350 reviews