【问题标题】:Need to understand this warning "Attributes on method implementation and its declaration must match"需要了解此警告“方法实现上的属性及其声明必须匹配”
【发布时间】:2013-08-14 08:17:26
【问题描述】:

我有一个 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 宏吗?

【问题讨论】:

  • 检查this answer,可能有用。
  • 该错误通常意味着您的方法标头与实现不同,例如您可能在 yourClass.h 文件中有 -(void)doSomething:(int) 参数,而在 yourClass.m 文件中有 -(void)doSomething:(NSString *) param { ... }。

标签: ios llvm compiler-warnings


【解决方案1】:

从实现文件中删除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

}

【讨论】:

  • 我知道这很容易解决。谢谢!
猜你喜欢
  • 2012-08-20
  • 1970-01-01
  • 1970-01-01
  • 2012-11-08
  • 2013-03-23
  • 2016-03-08
  • 1970-01-01
相关资源
最近更新 更多