如何弃用整个协议?

32

是否有可能废弃整个协议?我使用的是附带于iOS SDK 5.0 Beta 7的GCC编译器。

DEPRECATED_ATTRIBUTE似乎不起作用。

例如,以下两个语句不能编译:

  • @protocol DEPRECATED_ATTRIBUTE MyProtocol
  • @protocol MyProtocol DEPRECATED_ATTRIBUTE
1个回答

59

我自己没有尝试过,但我认为以下语法应该可行。

__attribute__ ((deprecated))
@protocol MyProtocol
@end

这与弃用整个接口以及单个方法的语法类似。

__attribute__ ((deprecated))
@interface MyClass
@end

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

哦。完全没想到那个。 - Hyperbole
13
我知道这很老了,但只作为一个旁注,最近的Clang版本中你可以使用__deprecated作为__attribute__ ((deprecated))的缩写。 - mszaro
6
__deprecated 与 clang 版本无关,它是由系统头文件 /usr/include/sys/cdefs.h 提供的。您还可以使用 __deprecated_msg("A note to the developers using it."),编译器将打印消息以及弃用通知。 - Jeremy Huddleston Sequoia

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接