Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

ios - Xcode 10.2 with Swift 5.0 compiler - protocol inheritance issue

We have a big issue with the current Xcode version (10.2).

There is a BasicViewController class with the following signature:

class BasicViewController: UIViewController, UITableViewDataSource, UITableViewDelegate

Then we have another class like ExampleViewController: BasicViewController which has some additional logic.

Now comes the tricky part...

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.

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?

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. BasicViewController.swift
  2. SomeOtherFile.swift
  3. ExampleViewController.swift

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...