Cyclic Reference - protocols and subclasses
- by blindJesse
I'm getting some cyclic reference (I think) problems between a few classes that require imported headers due to either subclassing or protocol definitions. I can explain why things are set up this way but I'm not sure it's essential. Basically these classes are managing reciprocal to-many data relationships.
The layout is this:
Class A imports Class B because it's a delegate of Class B and needs its protocol definition.
Class B imports Class C because it's a subclass of Class C.
Class C imports Class A because it's a delegate of Class A and needs its protocol definition.
Here's some sample code that illustrates the problem. The errors I'm getting are as follows: In Class A - "Can't find protocol definition for Class_B_Delegate".
In Class B - "Can't find interface declaration for Class C - superclass of Class B." In Class C - "Can't find protocol definition for Class_A_Delegate".
Class A header:
#import <Foundation/Foundation.h>
#import "Class_B.h"
@protocol Class_A_Delegate
@end
@interface Class_A : NSObject <Class_B_Delegate> {
}
@end
Class B header:
#import <Foundation/Foundation.h>
#import "Class_C.h"
@protocol Class_B_Delegate <NSObject>
@end
@interface Class_B : Class_C {
}
@end
Class C Header:
#import <Foundation/Foundation.h>
#import "Class_A.h"
@interface Class_C : NSObject <Class_A_Delegate> {
}
@end