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

查看:47
本文介绍了不推荐在 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 推理"设置设置为开",它允许旧代码工作.但是,它将显示需要解决的弃用警告.建议修复"这些警告并将设置切换为默认",这是新 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天全站免登陆