我刚刚查看了答案 here但没有帮助。当我只向方法声明添加一个弃用的属性时,编译器说 Attributes on method implementation and its declaration must match
。我需要在方法实现中添加 smth 吗?
谢谢!
最佳答案
只需将属性添加到声明中:
@interface Blah
- (void)method __attribute__((deprecated));
@end
只要您的包含对于翻译是正确的,这应该可以正常工作。也许您已将属性添加到定义,而不是声明?否则,演示(代码示例)会有所帮助。
更新
尽管上述方法适用于典型的消息,但 clang 似乎与 IBAction
混淆了。
使用 clang,ibaction
属性被隐式插入(对于以前的 typedef
)。
仅在声明中指定属性时,预处理器输出如下:
// preprocessed declaration
- (void)__attribute__((ibaction))setSomething:(id)sender __attribute__((noreturn));
// preprocessed implementation
- (void)__attribute__((ibaction))setSomething:(id)sender
...
因此,看起来编译器只是被这个隐藏的修饰弄糊涂了,您还必须将属性添加到实现/定义中,以在方法是 IBAction
时抑制警告。
关于ios - 如何正确弃用 Xcode 4 中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10100356/