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.
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
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.
I ran into the same issue. I fixed it by adding the methods directly in my main class, and override them in the other classes. Now everything gets called correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With