带有Swift 5.0编译器的Xcode 10.2-协议继承问题 [英] Xcode 10.2 with Swift 5.0 compiler - protocol inheritance issue
问题描述
当前的Xcode版本(10.2)存在一个大问题.
We have a big issue with the current Xcode version (10.2).
有一个带有以下签名的BasicViewController
类:
There is a BasicViewController
class with the following signature:
class BasicViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
然后我们有另一个像ExampleViewController: BasicViewController
的类,它具有一些附加的逻辑.
Then we have another class like ExampleViewController: BasicViewController
which has some additional logic.
现在是棘手的部分了...
Now comes the tricky part...
我们在不同的模拟器和设备上构建和运行该应用程序,并且一切正常.然后,我们将应用程序存档,突然不再触发didSelectRow
.对项目的彻底清理使我们能够重现该问题,而无需再次存档.
We build and run the app on different simulators and devices and everything works properly. Then we archive the app and suddenly didSelectRow
is not fired anymore. Deep clean and clean of the project allowed us to reproduce the issue without the need to archive again.
我想不出何时会发生这种情况.而且情况变得更糟,因为我发现更多类似的问题,仅当运行已存档的应用程序时,子类中未调用UITableViewDelegate
方法.在存档和提交应用程序期间进行某些优化可能会带来问题吗?
I cannot think of any case when this could happen. And it gets even worse, because I found more similar issues with UITableViewDelegate
methods not being called in the child class only when running the archived app. Could it be an issue with some of the optimisations during archiving and submitting the app?
我确认我们已正确设置表格的dataSource
和delegate
,表格上没有手势识别器.第二次/第三次运行该应用程序后,相同的逻辑效果很好,但在彻底清除项目后,第一次逻辑失败.
I verify that we set the dataSource
and delegate
of the table properly, there are no gesture recognisers over the table. The same logic works well after running the app second/third time, but fails first time after a deep clean of the project.
我们进行了测试,并在子类中设置了UITableViewDataSource
和UITableViewDelegate
,然后每次都能正常工作.似乎继承协议并不能很好地工作.如果我们将协议保留在父类中,并且也将其添加到子类中,则表明子类中的协议是多余的.
We made a test and set the UITableViewDataSource
and UITableViewDelegate
in the child class and then it works as expected every time. It seems inheriting the protocols does not work well. If we keep the protocols in the parent and also add them in the child class, then it says that the protocols in the child class are redundant.
有人经历过类似的经历吗?欢迎任何建议.
Has anyone experienced anything similar? Any suggestions are welcome.
推荐答案
您可能会遇到 https在Swift 5.0编译器中://://bugs.swift.org/browse/SR-10257 .如果您至少有三个文件,则会发生这种情况:
You may be running into https://bugs.swift.org/browse/SR-10257 in the Swift 5.0 compiler. This would happen if you have at least three files:
-
BasicViewController.swift
-
SomeOtherFile.swift
-
ExampleViewController.swift
BasicViewController.swift
SomeOtherFile.swift
ExampleViewController.swift
如果SomeOtherFile.swift
对AnyObject
类型的值进行了任何调用,则您将以wholemodule
模式进行编译,并且文件将以上述顺序传递给编译器(其中SomeOtherFile.swift
位于中间两者),那么似乎编译器无法正确地推断@objc
-ness来实现func tableView(_:, didSelectRowAt:)
.您可以通过暂时用@objc
明确标记它来解决它.
If SomeOtherFile.swift
makes any calls to an AnyObject
-typed value, you're compiling in wholemodule
mode, and the files are passed to the compiler in the above order (with SomeOtherFile.swift
in the middle of the two), then it seems that the compiler fails to properly infer @objc
-ness for the implementation of func tableView(_:, didSelectRowAt:)
. You can work around it by explicitly tagging it with @objc
for now.
这篇关于带有Swift 5.0编译器的Xcode 10.2-协议继承问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!