I have a project structure in which:
• ClassA
has a strong reference to ClassB
• ClassAA
subclasses ClassA
and has a strong reference to ClassBB
• ClassB
has a weak reference to ClassA
(named state
and defined using @class ClassA;
)
• ClassBB
subclasses ClassB
and overloads state
to be ClassAA
and uses @class ClassAA;
to do so
Because of the overloaded state
in ClassBB
, the compiler can't tell that ClassAA
is a subclass of ClassA
. Thus, I get this warning:
Property type 'ClassAA *' is incompatible with type 'ClassA *' inherited from 'ClassB'`
How can I tell the compilter that I know what I'm doing, so the warning hides itself? Thanks for any advice. Below is the project structure that creates this warning:
ClassA.h
#import <Foundation/Foundation.h>
#import "ClassB.h"
@interface ClassA : NSObject
@property (strong)
ClassB* view;
@end
ClassB.h
#import <UIKit/UIKit.h>
@class ClassA;
@interface ClassB : UIView
@property (weak)
ClassA* state;
@end
ClassAA.h (inherits from ClassA)
#import "ClassA.h"
#import "ClassBB.h"
@interface ClassAA : ClassA
@property (strong)
ClassBB* view;
@end
ClassBB.h (inherits from ClassB)
#import "ClassB.h"
@class ClassAA;
@interface ClassBB : ClassB
@property (weak)
ClassAA* state; <-- Where the warning is occurring
@end
@class ClassAA
forward declaration? I also wonder whether the property needs to be in the public @interface, in which case you could move it to the .m and get the same effect. – stevesliva@class
is because circular dependencies are not allowed. And I would prefer to keep it in the public @interface, sorry. – aleclarson