26 lines
832 B
Swift
26 lines
832 B
Swift
//
|
|
// MastodonServerRulesViewModel+Diffable.swift
|
|
// Mastodon
|
|
//
|
|
// Created by MainasuK on 2022-1-5.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
extension MastodonServerRulesViewModel {
|
|
func setupDiffableDataSource(
|
|
tableView: UITableView
|
|
) {
|
|
diffableDataSource = ServerRuleSection.tableViewDiffableDataSource(tableView: tableView)
|
|
|
|
var snapshot = NSDiffableDataSourceSnapshot<ServerRuleSection, ServerRuleItem>()
|
|
snapshot.appendSections([.rules])
|
|
let ruleItems: [ServerRuleItem] = rules.enumerated().map { i, rule in
|
|
let ruleContext = ServerRuleItem.RuleContext(index: i, rule: rule)
|
|
return ServerRuleItem.rule(ruleContext)
|
|
}
|
|
snapshot.appendItems(ruleItems, toSection: .rules)
|
|
diffableDataSource?.apply(snapshot, animatingDifferences: false)
|
|
}
|
|
}
|