ra1028 / DiffableDataSources

💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.
https://ra1028.github.io/DiffableDataSources
Apache License 2.0
852 stars 68 forks source link

Missing UITableViewDiffableDataSource methods for edit/move rows #16

Closed bobek-balinek closed 4 years ago

bobek-balinek commented 4 years ago

Thank you for creating this project, it's become really useful in few of my projects!

However I have noticed few methods from the official UITableViewDiffableDataSource are missing from your implementation:

Reference: https://developer.apple.com/documentation/uikit/uitableviewdiffabledatasource

Naturally I'd expect these methods to be open and overridable to be able to construct and apply a new snapshot separately.

Expected Behavior

Subclassing the TableViewDiffableDataSource should allow to override and provide a custom implementation for canEditRowAt/canMoveRowAt protocol methods.

class MyDiffableDataSource: TableViewDiffableDataSource<SectionViewModel, AnyViewModel> {
    func tableView(_: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }

    func tableView(_: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        // Custom implementation
    }
}

Current Behavior

Methods canEditRowAt and commit:editingStyle:forRowAt do not get executed when implemented on a subclass. This is probably because the base class does not provide an open/public default implementations for these.

tako3 commented 4 years ago

You can override canEditRowAt, canMoveRowAt , etc by adding @objc annotation:

@objc(tableView:canEditRowAtIndexPath:)
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
    true 
}

FMI see Stack Overflow Swift 3 ObjC Optional Protocol Method Not Called in Subclass.

ra1028 commented 4 years ago

@bobek-balinek

Sorry for my late reply. I’m a bit busy lately, so please feel free to make a pull request!

Until fixed, please do a good workaround by @tako3 .