Srujan Simha Adicharla
Srujan Simha Adicharla

Reputation: 3723

Swift 3: Tableview datasource methods "Overriding non-open instance method outside of its defining module" error

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.

Upvotes: 6

Views: 13274

Answers (1)

Xvolks
Xvolks

Reputation: 2155

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

See What is the 'open' keyword in Swift?

Upvotes: 11

Related Questions