Getting error when using default init for diffableDataSource

I was trying to create subclass for UITableViewDiffableDataSource, but encountered

**Fatal error: Use of unimplemented initializer 'init()' for class 'UIKit.UITableViewDiffableDataSource'**

while trying to use default initializer.

while trying to use default initializer.

How are you doing that? It sounds like you’re calling super.init, which isn’t going to work [1]. You need to call super.init(tableView:cellProvider:). For example:

class MyDiffableDataSource: UITableViewDiffableDataSource<String, String> {
    override init(tableView: UITableView, cellProvider: @escaping UITableViewDiffableDataSource<String, String>.CellProvider) {
        super.init(tableView: tableView, cellProvider: cellProvider)
        // super.init()

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

[1] It’s weird that Swift lets you do that because the default initialiser is marked as unavailable in the Objective-C header:

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;