From 08b8cd3a3e6f865883573d3eff844b3a8ac7f892 Mon Sep 17 00:00:00 2001 From: sanghyeok-kim Date: Fri, 4 Aug 2023 08:05:32 +0900 Subject: [PATCH] =?UTF-8?q?#8=20feat:=20RingtoneSelectTableViewDiffableDat?= =?UTF-8?q?aSource=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...oneSelectTableViewDiffableDataSource.swift | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Multimer/Multimer/Presentation/RingtoneSelect/RingtoneSelectTableViewDiffableDataSource.swift 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 + } +}