Nic*_*ght 40 function objective-c deprecated
有谁知道如何做到这一点?
我猜这里有一些关键字,我可以在某个地方找到这个功能后坚持下去?
编辑:我想在任何人尝试使用已弃用的函数时生成编译器警告,类似于Apple的API中的行为.
干杯! 缺口.
Tim*_*Tim 61
尝试在方法声明中附加属性:
- (void)fooBar __attribute__ ((deprecated));
Run Code Online (Sandbox Code Playgroud)
取自这里.
小智 7
蒂姆的回答实际上会产生编译警告; 其他版本只是对编译器没有影响的注释.
如果你看一下/usr/include/AvailabilityMacros.h,你就会看到Apple是如何做到这一点的.该标头使用__attribute__((deprecated))
并__attribute__((unavailable))
取决于API是否存在但已弃用,或者实际已从操作系统中删除.
代替__attribute__((deprecated))
,您可以使用在中定义的宏<cdefs.h>
:
- (void)fooBar __deprecated;
// Or better:
- (void)fooBar __deprecated_msg("Use barFoo instead.");
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用在中定义的宏<AvailabilityMacros.h>
:
- (void)fooBar DEPRECATED_ATTRIBUTE;
// Or better:
- (void)fooBar DEPRECATED_MSG_ATTRIBUTE("Use barFoo instead.");
Run Code Online (Sandbox Code Playgroud)
如果您使用Objective-C,则因为使用现代编译器没有什么区别,因此可以使用Apple短语法__deprecated_msg()
。但是,如果将C用于跨平台,则DEPRECATED_MSG_ATTRIBUTE()
使用最佳可用性定义(例如,它支持GCC3.1)。
归档时间: |
|
查看次数: |
12188 次 |
最近记录: |