I created a BaseRequest
Class and it has a property params
, which is an id
that conforms to the <BaseParams>
protocol.
Next I created a DiagramRequest
Class inherited from BaseRequest
and it has a property whose type is DiagramParam
, which is class that conforms to the <BaseParams>
protocol.
I think it is safe for compiling, but Xcode still warns that:
Property type 'DiagramParams *' is incompatible with type 'id<BaseParams>' inherited from 'BaseRequest'
I wonder why.
Simplified Demo is here:
BaseRequest.h
@interface BaseRequest
@property (nonatomic,retain) id<BaseParams> params;
@end
@protocol BaseParams <NSObject>
- (NSMutableDictionary *)getParamsDict;
@end
DiagramRequest.h
@interface DiagramRequest : BaseRequest
//warning: Property type 'DiagramParams *' is incompatible with type 'id<BaseParams>' inherited from 'BaseRequest'
@property (nonatomic,retain) DiagramParams *params;
@end
@interface DiagramParams : NSObject <BaseParams>
@property (nonatomic) int id;
@property (nonatomic,retain) NSString *city;
- (NSMutableDictionary *)getParamsDict;
@end
The warning might be removed by placing the DiagramParams
's interface definition before DiagramRequest
's.
See my answer here.. https://stackoverflow.com/a/14632135/1347502 which removes the warning for a slightly simpler setup.