Make an extensions of generic class in Swift4

The error message seems very clear. This isn't supported. You can't attach an @objc method to a generic class in an extension. You need to define these methods in the class definition, not an extension. The "why" is "the compiler doesn't support it today." (It's likely hard to support because of specializations, but the real answer is "the compiler can't do it.")


Currently the Xcode doesn't support attach an @objc method to a generic class in an extension, you can fix it by define the method inside the class definition, as following:

class Foo<T>: UIViewController, UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        //Code here ...
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //Code here ...
    }
}