如何正确弃用Xcode 4中的方法 [英] How to properly deprecate a method in Xcode 4

查看:69
本文介绍了如何正确弃用Xcode 4中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在此处中查看了答案,但是没有帮不上忙.当我仅向方法声明中添加不推荐使用的属性时,编译器会说Attributes on method implementation and its declaration must match.我需要在方法实现中添加smth吗?

I've just looked over the answers here but didn't help. When I add a deprecated attribute only to method declaration than the compiler says Attributes on method implementation and its declaration must match. Do I need to add smth to method implementation?

谢谢!

推荐答案

只需将属性添加到声明中即可:

Just add the attribute to the declaration:

@interface Blah
- (void)method __attribute__((deprecated));
@end

如果您提供的包含词对翻译正确,则应该可以正常工作.也许您已将属性添加到定义,而不是声明?否则,演示(代码示例)会有所帮助.

Provided your includes are correct for the translation, this should work fine. Perhaps you have added the attribute to the definition, not the declaration? Otherwise, a demonstration (code sample) would help.

更新

尽管以上方法适用于典型消息,但似乎clang与IBAction混淆了.

Although the above approach works for typical messages, it appears clang gets confused with IBActions.

使用clang时,将隐式插入ibaction属性(对于以前的typedef).

With clang, ibaction attributes are implicitly inserted (for what was formerly a typedef).

仅在声明中指定属性时,预处理器输出如下:

When the attribute is specified in the declaration only, the preprocessor output is as follows:

// preprocessed declaration
- (void)__attribute__((ibaction))setSomething:(id)sender __attribute__((noreturn));
// preprocessed implementation
- (void)__attribute__((ibaction))setSomething:(id)sender
...    

因此,似乎编译器只是被这种隐藏的修饰所迷惑,并且当方法为IBAction时,还必须将属性添加到实现/定义中以禁止显示警告.

So, it appears the compiler is just confused by this hidden decoration, and you must also add the attribute to the implementation/definition to suppress the warning when the method is an IBAction.

这篇关于如何正确弃用Xcode 4中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆