DenTelezhkin / DTTableViewManager

Protocol-oriented UITableView management, powered by generics and associated types.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TableViewUpdater for local search

EngrAhsanAli opened this issue · comments

Hello!

I am wondering if TableViewUpdater can be used to filter local searches. For instance, I do search a specific text for all sections like below:

manager.memoryStorage.sections.enumerated().forEach {
            let section = $0.element
            for i in 0...section.numberOfItems - 1 {
                let item = section.item(at: I)
                // Conditions if matched  
                let indexPath = IndexPath(item: i, section: $0.offset)
                indexPaths.append(indexPath) // result array
            }
        }

So how the data will be provided to TableViewUpdater to load only these specific IndexPaths?

P.S:- Any other good approach to filter local data?

Hi!

If you support iOS 13 and higher, you can use diffable datasources, for which DTTableViewManager provides convenience wrapper. There is an example provided in this repo for how this can be done for multisectioned data(example here)

If you need to support lower iOS and have only one section of data, for which you want to provide delta updates, there is SingleSectionEquatableStorage wrapper, that can do that for you. Example project contains sample of this as well(sample here). This example uses DTTableViewManager and Changeset frameworks.

If none of those two options work for you, you can always filter sections manually, and set new sections on MemoryStorage. Unfortunately, in this case, all UITableView will get reloaded, and will not provide you delta updates. You can also try to calculate changes manually and apply them to UITableView, but since it's more complicated than other options, I would not recommend it.