不建议在Swift 4模式下使用Swift 3 @objc推论吗? [英] The use of Swift 3 @objc inference in Swift 4 mode is deprecated?

查看:171
本文介绍了不建议在Swift 4模式下使用Swift 3 @objc推论吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之,在使用Xcode 9 Beta时,我遇到了以下警告:

Briefly, while using Xcode 9 Beta, I have run into the following warning:

不建议在Swift 4模式下使用Swift 3 @objc推论.请解决已弃用的@objc推理警告,启用使用已弃用的Swift 3 @objc推理"日志记录来测试您的代码,并禁用Swift 3 @objc推理.**

The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with "Use of deprecated Swift 3 @objc inference" logging enabled, and disable Swift 3 @objc inference.**

经过研究,我仍然不知道如何解决该问题. 我将不胜感激有关如何解决此问题的所有技巧以及对所发生问题的解释.

After some research, I still have no idea how to fix the issue. I would greatly appreciate any tips on how to fix this issue as well as an explanation of what is going on.

我的目标是更好地理解我的代码正在发生的事情.

My goal is to grasp a better understanding of what is happening with my code.

推荐答案

我通过更改"Swift 3 @objc Inference"来消除此警告.将目标设置为默认".

I got rid of this warning by changing the "Swift 3 @objc Inference" build setting of my targets to "Default".

来自本文:

在Swift 4之前,编译器自动向Objective-C提供了一些 Swift声明.例如,如果从NSObject继承了一个子类,则编译器会为此类中的所有方法创建Objective-C入口点.该机制称为@objc推断.

Before Swift 4, the compiler made some Swift declarations automatically available to Objective-C. For example, if one subclassed from NSObject, the compiler created Objective-C entry points for all methods in such classes. The mechanism is called @objc inference.

在Swift 4中,不建议使用这种自动@objc推断,因为生成所有这些Objective-C入口点的成本很高.当"Swift 3 @objc Inference"时,设置被设置为开",它允许旧代码工作.但是,它将显示需要解决的弃用警告.建议修复"文件中的内容.这些警告,然后将设置切换为默认" ,这是新Swift项目的默认设置.

In Swift 4, such automatic @objc inference is deprecated because it is costly to generate all those Objective-C entry points. When "Swift 3 @objc Inference" setting is set to "On", it allows the old code to work. However, it will show deprecation warnings that need to be addressed. It is recommended to "fix" these warnings and switch the setting to "Default", which is the default for new Swift projects.

另请参阅此Swift提案了解更多信息.

Please also refer to this Swift proposal for more information.

这篇关于不建议在Swift 4模式下使用Swift 3 @objc推论吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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