6

I have an open BaseViewController class in core framework that has tableview datasource methods implemented. Let's say I've another class (outside the module) ClassA with BaseViewController as it's superclass. When I try to override tableview datasource methods, it's throwing this error Overriding non-open instance method outside of its defining module.

BaseViewController looks like this

open class BaseViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

...

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 0
}

public func numberOfSections(in tableView: UITableView) -> Int {
    return 0
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    return UITableViewCell()
  }
}

ClassA

import CustomCoreFramework

class ClassA : BaseViewController {

// throws an error
public override func numberOfSections(in tableView: UITableView) -> Int {
    return tableViewListItems.count
}

}

I suppose the open class methods should be accessible outside the module. I tried changing the tableview methods access specifiers to public and different combinations but nothing seems to work.

Srujan Simha
  • 3,637
  • 8
  • 42
  • 59

1 Answers1

11

The BaseViewController’s methods should be declared open. This is discuss in the thread in reference.

See What is the 'open' keyword in Swift?

Xvolks
  • 2,065
  • 1
  • 21
  • 32
  • I tried that before, it didn't work but now it did. I don't know why!! I'm glad that it worked and also pissed because it didn't work before. Thanks anyway. – Srujan Simha Aug 18 '17 at 19:41