Skip to content

DiffableDatasource with Combine framework at MVVM pattern

Notifications You must be signed in to change notification settings

kostasfilios/DiffableCombineExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

DiffableCombineExample

This is an example with usage od DiffableDatasource with Combine framework at MVVM pattern.

  1. We create our DiffableDatasource
func makeDataSource() -> UITableViewDiffableDataSource<Section, User> {
        return UITableViewDiffableDataSource(
            tableView: tableView,
            cellProvider: {  tableView, indexPath, user in
                let cell = UserTableViewCell.dequeueInTableView(tableView, forIndexPath: indexPath)
                cell.configureCell(with: user)
                return cell
            })
    }
  1. We make a Published response to use it for emiting changes over combine framework
@Published var response: ViewState<[User]> = .loading
  1. We hande the response over a ViewState enum
private func handle(response: ViewState<[User]>?) {
        switch response ?? .loading {
        case .loading:
            loadingIndicator.isHidden = false
            break
        case .error(_):
            break
        case .loaded(let data):
            loadingIndicator.isHidden = true
            insert(list: data) }
    }

About

DiffableDatasource with Combine framework at MVVM pattern

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages