-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8 feat: RingtoneSelectTableViewDiffableDataSource 구현
- Loading branch information
1 parent
3ec697d
commit 08b8cd3
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...imer/Multimer/Presentation/RingtoneSelect/RingtoneSelectTableViewDiffableDataSource.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |