gpt4 book ai didi

swift - 在 Swift 4 模式下使用 Swift 3 @objc 推理是否被弃用?

转载 作者:IT王子 更新时间:2023-10-29 04:54:33 26 4
gpt4 key购买 nike

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

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.**

经过一些研究,我仍然不知道如何解决这个问题。我将非常感谢有关如何解决此问题的任何提示以及对正在发生的事情的解释。

我的目标是更好地理解我的代码发生了什么。

最佳答案

我通过将目标的“Swift 3 @objc Inference”build设置更改为“默认”来消除此警告。

Disable Swift 3 @objc inference in Xcode9

来自 this article :

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.

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.

另请引用this Swift proposal获取更多信息。

关于swift - 在 Swift 4 模式下使用 Swift 3 @objc 推理是否被弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44379348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com