【发布时间】:2012-04-23 10:17:03
【问题描述】:
我刚刚查看了here 的答案,但没有帮助。当我只在方法声明中添加不推荐使用的属性时,编译器会说Attributes on method implementation and its declaration must match。我需要在方法实现中添加 smth 吗?
谢谢!
【问题讨论】:
标签: ios xcode xcode4 methods deprecated
我刚刚查看了here 的答案,但没有帮助。当我只在方法声明中添加不推荐使用的属性时,编译器会说Attributes on method implementation and its declaration must match。我需要在方法实现中添加 smth 吗?
谢谢!
【问题讨论】:
标签: ios xcode xcode4 methods deprecated
只需将属性添加到声明中:
@interface Blah
- (void)method __attribute__((deprecated));
@end
如果您的包含对翻译是正确的,这应该可以正常工作。也许您已将属性添加到定义,而不是声明?否则,演示(代码示例)会有所帮助。
更新
虽然上述方法适用于典型消息,但似乎 clang 与 IBActions 混淆了。
使用 clang,ibaction 属性被隐式插入(对于以前的 typedef)。
仅在声明中指定属性时,预处理器输出如下:
// preprocessed declaration
- (void)__attribute__((ibaction))setSomething:(id)sender __attribute__((noreturn));
// preprocessed implementation
- (void)__attribute__((ibaction))setSomething:(id)sender
...
所以,编译器似乎只是被这种隐藏的装饰弄糊涂了,当方法是IBAction 时,您还必须将属性添加到实现/定义中以抑制警告。
【讨论】:
IBActions -- 见更新。
您必须将 deprecated 属性放在方法的声明和实现中,至少在带有 clang 的 Xcode 4.3.2 中。
【讨论】: