需要理解这个警告“方法实现的属性及其声明必须匹配”

时间:2013-08-14 08:17:26

标签: ios llvm compiler-warnings

我有一个UIView子类用作自定义警报视图,它声明了这个init方法

@interface THAlertView : UIView   
- (id) initWithTitle:(NSString *)title message:(NSString *)message
    cancelButtonTitle:(NSString*)cancelButtonTitle
    otherButtonTitles:(NSString*)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
@end

在实现文件中,我只是定义了该方法

@implementation THAlertView

- (id) initWithTitle:(NSString *)title message:(NSString *)message
   cancelButtonTitle:(NSString*)cancelButtonTitle
   otherButtonTitles:(NSString*)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION {

// Create and return an instance of THAlertView

}

带有LLVM 4.2的XCode 4.6.3给了我这个警告

THAlertView.m:74:193: warning: attributes on method implementation and its declaration must match [-Wmismatched-method-attributes]
- (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString*)cancelButtonTitle otherButtonTitles:(NSString*)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION {
                                                                                                                                                                                               ^
THAlertView.h:29:1: note: method 'initWithTitle:message:cancelButtonTitle:otherButtonTitles:' declared here
- (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString*)cancelButtonTitle otherButtonTitles:(NSString*)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
^
1 warning generated.

我明白警告是什么,但这次我不知道如何解决它。对我来说一切似乎都很好,但也许我错过了一些东西。可能是因为NS_REQUIRES_NIL_TERMINATION宏吗?

1 个答案:

答案 0 :(得分:5)

从实施文件中删除NS_REQUIRES_NIL_TERMINATION

@implementation THAlertView

- (id) initWithTitle:(NSString *)title message:(NSString *)message
   cancelButtonTitle:(NSString*)cancelButtonTitle
   otherButtonTitles:(NSString*)otherButtonTitles, ... {

// Create and return an instance of THAlertView

}