我怎么能告诉Clang忽略`与[超类]属性类型`警告不兼容的属性?

时间:2014-04-07 23:33:59

标签: ios xcode clang

我有一个像这样的超级课程:

@protocol AOCellDelegate;

@interface AOBaseCell : UITableViewCell
@property (nonatomic, weak) id<AOCellDelegate>delegate;
// ... other stuff ...
@end

其中AOCellDelegate在单独的AOCellDelegate.h文件中声明(并非所有控制器都关心是单元委托,因此我不想强制它们导入它)。

我有一个AOBaseCell的子类,如下所示:

@protocol AOTextCellDelegate;

@interface AOTextCell : AOBaseCell
@property (nonatomic, weak) id<AOTextCellDelegate>delegate;
// ... other stuff...
@end

AOTextCellDelegateAOTextCellDelegate.h中声明AOCellDelegate符合@protocol AOTextCellDelegate <AOCellDelegate> // ... methods ... @end 的情况:

property type 'id<AOTextCellDelegate>' is incompatible with type 'id<AOCellDelegate>' inherited from 'AOBaseCell'

Xcode / Clang错误地给出了此警告:

AOTextCellDelegate

兼容,因为AOCellDelegate符合AOTextCellDelegate.h,但Clang无法说明这一点,因为AOTextCell.h未导入#pragma

如何告诉Xcode / Clang仅在此文件中忽略此警告?

根据这个other StackOverflow question,我认为我需要使用{{1}}来忽略它。但是,我没有在日志中看到警告标识符(只是上面的消息)。

1 个答案:

答案 0 :(得分:0)

我无法找到使用#pragma来消除此警告的方法。但是,通过执行以下操作,我能够让Clang知道子类delegate属性与超级delegate属性兼容:

@protcol AOCellDelegate; // technically, not needed because it's imported from super header
@protocol AOTextCellDelegate;

@interface AOTextCell : AOBaseCell
@property (nonatomic, weak) id<AOCellDelegate, AOTextCellDelegate>delegate;
// ... other stuff...
@end