2012-12-18 77 views
1

我创建了一个BaseRequest类,它具有一个符合BaseParams协议的属性。 和接下来我创建了一个从BaseRequest继承的DiagramReqesut类,它有一个类型为DiagramParam的属性也符合BaseParams协议。属性类型''与继承自''的类型''不兼容''

我认为这是编译安全的,但仍Xcode中警告说: 房产类型“DiagramParams *”是类型“ID”不兼容从“BaseRequest”继承

我不知道为什么。

简化演示是在这里:

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 

回答

2

可以通过在第一个接口定义之前放置第二个接口定义来删除警告。

看到我的答案在这里.. https://stackoverflow.com/a/14632135/1347502它删除了一个稍微简单的设置警告。

+0

它的工作原理,谢谢〜 – Feather

0

我有一类DTTextRange同样的问题,这是UITextRange和所有的子类UITextInput方法需要UITextRange这是一个抽象类。

如果我有一个属性selectedTextRange,它指定DTTextRange为类型,并获得与DTTextRange与UITextRange不兼容的警告。

我能够解决这个问题的唯一方法就是在我的财产中使用超类。

总之,我希望能够做到与你一样,让我们​​知道如果你找到一种方式来改变属性类型。

如果不是,则必须删除子类属性并使用该id。