Skip to content

Commit

Permalink
#8 feat: RingtoneSelectTableViewDiffableDataSource 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
sanghyeok-kim committed Aug 3, 2023
1 parent 3ec697d commit 08b8cd3
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// RingtoneSelectTableViewDiffableDataSource.swift
// Multimer
//
// Created by 김상혁 on 2023/08/02.
//

import UIKit

final class RingtoneSelectTableViewDiffableDataSource: UITableViewDiffableDataSource<RingtoneType, RingtoneCellModel> {

typealias Snapshot = NSDiffableDataSourceSnapshot<RingtoneType, RingtoneCellModel>

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
}
}

0 comments on commit 08b8cd3

Please sign in to comment.