批量修复数百个“#selector 未暴露于 Objective-C"Xcode 9 或 9.1 中的错误 [英] Bulk fix hundreds of "#selector not exposed to Objective-C" errors in Xcode 9 or 9.1

查看:25
本文介绍了批量修复数百个“#selector 未暴露于 Objective-C"Xcode 9 或 9.1 中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以通过添加'@objc'来将这个实例方法暴露给Objective-C来一次修复多个错误,在我完成修复之后,我实际上有超过200个这样的错误70个错误,一一做就累了.

Is there any way to fix multiple errors at once by Adding '@objc' to expose this instance method to Objective-C, I actually had over 200 of these errors, after I done fixed about 70 errors, got tired sick if doing this one by one.

我尝试在 issue navigator 中选择多个这些错误,但没有立即看到 Fix 的方法.

I tried selecting multiple of these errors in issue navigator but dont see a way of Fix at once.

我看到的唯一方法是一次选择一个错误并点击Fix,哦,这令人作呕,如果您知道任何方法,请帮助.

The only way I see is to select one error at a time and hit Fix, ooh this is sickening, please help if you know any way.

推荐答案

您需要运行迁移器 – 在 Xcode 中转到Edit > Convert > To Current Swift Syntax...",然后选择Minimize Inference"Swift 4 @objc inference"选项(我实际上直到最近才意识到迁移器所做的大部分事情只是自动应用编译器修复).

You'll want to run the migrator – go "Edit > Convert > To Current Swift Syntax..." in Xcode, and select "Minimize Inference" for the "Swift 4 @objc inference" option (I actually didn't realise until recently that the most of what the migrator does is just automatically applying compiler fix-its).

如果您已经在 Swift 4 目标中,您将无法在其上运行迁移.您可以通过将该目标的Swift 语言版本"构建设置更改为Swift 3.2",然后在其上运行迁移器(这会将版本切换回 4)来解决此问题.

If you're already in a Swift 4 target, you won't be able to run migration on it. You can fix this by just changing the "Swift Language Version" build setting to "Swift 3.2" for that target, and then running the migrator on it (which will switch the version back to 4).

迁移器运行后,您会注意到Swift 3 @objc inference"构建设置已设置为On"——您需要使用此构建设置来测试您的程序,以确保您不会获取有关未标记为 @objc 的 Obj-C 入口点的任何运行时警告,然后在完成后将构建设置更改为默认",如在本问答中.

After the migrator has run, you'll notice that the "Swift 3 @objc inference" build setting has been set to "On" – you'll want to test your program with this build setting to ensure you don't get any runtime warnings about Obj-C entrypoints that aren't marked as @objc, and then change the build setting to "Default" when done, as discussed in this Q&A.

此外,在迁移之后,请随意查看添加了 @objc 的地方 - 您可以使用单个 @objc 扩展名 的给定类来定义一组要公开给 Obj-C 的方法.如果您正在查看一个需要为所有兼容成员公开 Obj-C 的类,那么您可以标记该类@objcMembers.有关详细信息,请参阅此问答.

Additionally, after migration, feel free to look over the places where @objc has been added – you may be able to neaten code up by using a single @objc extension of the given class to define a group of methods that you want to expose to Obj-C. If you're looking at a class that requires Obj-C exposure for all its compatible members, then you can mark the class @objcMembers. See this Q&A for more info on that.

这篇关于批量修复数百个“#selector 未暴露于 Objective-C"Xcode 9 或 9.1 中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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