加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

__attribute__((不推荐使用))在Objective-C协议方法上不起作用?

发布时间:2020-12-14 20:04:43 所属栏目:百科 来源:网络整理
导读:我需要在 objective-c协议中弃用一种方法.在正常的类/实例方法中,我添加__attribute__((不推荐使用));宣布后 看来,它对协议方法不起作用.如果我们将它们标记为不推荐,并在项目编译的地方使用它们,而不需要预期的弃用警告. 这是苹果LLVM 3.1的缺陷,还是我做错
我需要在 objective-c协议中弃用一种方法.在正常的类/实例方法中,我添加__attribute__((不推荐使用));宣布后

看来,它对协议方法不起作用.如果我们将它们标记为不推荐,并在项目编译的地方使用它们,而不需要预期的弃用警告.

这是苹果LLVM 3.1的缺陷,还是我做错了?

解决方法

虽然这里的答案提供了一些非常好的信息,但它们已经过时了.从 Xcode 5.0和LLVM 5.0开始,它被认为是Objective-C协议方法的弃用警告.在实现该方法时,Xcode 5标记它:

Warning: Implementing deprecated method

以下是用于为执行不推荐使用的协议方法产生废弃警告的步骤:

>使用__deprecated标记协议方法已弃用.从新的SDK 7.0文档:

__deprecated causes the compiler to produce a warning when encountering code using the deprecated functionality. __deprecated_msg() does the same,and compilers that support it will print a message along with the deprecation warning. This may require turning on such warning with the -Wdeprecated flag. __deprecated_enum_msg() should be used on enums,and compilers that support it will print the deprecation warning.

#define __deprecated    __attribute__((deprecated))

要弃用您的方法,请执行以下操作:

- (void)aDeprecatedProtocolMethod __deprecated;

这一点应该足以让Xcode显示一个弃用警告.但是,您应该遵循接下来的几个步骤(知道Xcode可以非常有趣),以确保显示警告.
>使用废弃警告标签添加文档注释.请参阅下面的代码示例来了解如何:

/** Describe the method here - what does it do,how does it work,etc. Very brief.
    @deprecated This delegate method is deprecated starting in version 2.0,please use otherMethodNameHere:withAnExtraParameter: instead. */
- (void)aDeprecatedProtocolMethod __deprecated;

>清理项目(??K),然后构建项目(?B) – 只是因为有时候Xcode可能很时髦.

我不是100%肯定这个功能的引入时间(可能与SDK 7.0和10.9,或Xcode 5.0 / 5.0.1或LLVM 5.0) – 但它仍然工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读