diff --git a/Multimer/Multimer/Presentation/RingtoneSelect/RingtoneSelectTableViewDiffableDataSource.swift b/Multimer/Multimer/Presentation/RingtoneSelect/RingtoneSelectTableViewDiffableDataSource.swift new file mode 100644 index 0000000..5a3b604 --- /dev/null +++ b/Multimer/Multimer/Presentation/RingtoneSelect/RingtoneSelectTableViewDiffableDataSource.swift @@ -0,0 +1,42 @@ +// +// RingtoneSelectTableViewDiffableDataSource.swift +// Multimer +// +// Created by κΉ€μƒν˜ on 2023/08/02. +// + +import UIKit + +final class RingtoneSelectTableViewDiffableDataSource: UITableViewDiffableDataSource { + + typealias Snapshot = NSDiffableDataSourceSnapshot + + init(tableView: UITableView) { + super.init(tableView: tableView) { (tableView, indexPath, cellViewModel) -> UITableViewCell? in + let cell = tableView.dequeueReusableCell( + withIdentifier: RingtoneViewCell.identifier, + for: indexPath + ) as? RingtoneViewCell + let ringtoneName = LocalizableString.ringtoneName(ringtone: cellViewModel.ringtone).localized + cell?.configure(title: ringtoneName, isSelected: cellViewModel.isSelected) + return cell + } + } + + // MARK: - DiffableDataSource Methods + + func applySnapshot(for ringtoneCellModelMap: [RingtoneType: [RingtoneCellModel]]) { + var snapshot = Snapshot() + snapshot.appendSections(RingtoneType.allCases) + for type in RingtoneType.allCases { + if let cellModels = ringtoneCellModelMap[type] { + snapshot.appendItems(cellModels, toSection: type) + } + } + apply(snapshot, animatingDifferences: false) + } + + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + return RingtoneType.allCases[section].title + } +}