I have the following class hierarchy:
class ScrollableViewController: UIViewController, UITableViewDelegate { // ... }
That implements one UITableViewDelegate
protocol method, e.g. tableView:willDisplayCellAt:
In my class SpecificScrollableViewController
, which inherits from ScrollableViewController
, new optional protocol methods don't get called any more, e.g. tableView(_:heightForRowAt:)
This appears to be fixed in Swift 3.0.1 for normal subclasses, but is not fixed for generic subclasses:
See: https://bugs.swift.org/browse/SR-2817
To fix it: https://stackoverflow.com/a/39416386/1109892
tl;dr you need to prefix the function declaration with its Objective-C declaration, e.g.
I was tipped off to this being a solution thanks to the Swift 3 Migration Guide which states:
I'm fairly certain this is a bug: it appears that the the runtime dynamism that allows checking for selector capability does not get properly bridged in the Grand Swift Renaming when the protocol method is in the subclass. Prefixing the function declaration with the Objective-C name properly bridges the Swift to Objective-C and allows Swift 3 renamed methods to be queried with
canPerformAction:withSender:
from within Objective-C