ios - 如何正确弃用 Xcode 4 中的方法

标签 ios xcode xcode4 methods deprecated

我刚刚查看了答案 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/

相关文章:

ios - 链接器命令失败错误,xcode?

ios - 无法在 iOS 设备上运行 XCTests

iOS;使用 ZXing 2.0,无法使用 Xcode 4.2 链接到 libZXingWidget.a

objective-c - 之间的实际差异 - (IBAction)pushClear :(id)sender and - (IBAction)pushClear:(NSButton)sender

ios - Objective-C ,线程 1 程序接收信号 SIGABRT

ios - 为什么即使我在 NSDateFormatter 上设置了时区,stringFromDate NSString 仍然有 GMT 时间?

ios - 如何使用 Facebook SDK 3.1 避免 "App is allready authorized"

xcode - 如何在 swift 中实例化 NSLayoutConstraint? (Xcode 6.1.1)

iOS Soundcloud 登录问题

ios - 设置另一个 UIViewController 的属性