SelectedAccountSection.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // SelectedAccountSection.swift
  3. // Mastodon
  4. //
  5. // Created by sxiaojian on 2021/4/22.
  6. //
  7. import UIKit
  8. import CoreData
  9. import CoreDataStack
  10. import MastodonCore
  11. import MastodonSDK
  12. enum SelectedAccountSection: Equatable, Hashable {
  13. case main
  14. }
  15. extension SelectedAccountSection {
  16. static func collectionViewDiffableDataSource(
  17. collectionView: UICollectionView,
  18. context: AppContext
  19. ) -> UICollectionViewDiffableDataSource<SelectedAccountSection, SelectedAccountItem> {
  20. UICollectionViewDiffableDataSource(collectionView: collectionView) { collectionView, indexPath, item -> UICollectionViewCell? in
  21. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: SuggestionAccountCollectionViewCell.self), for: indexPath) as! SuggestionAccountCollectionViewCell
  22. switch item {
  23. case .account(let record):
  24. context.managedObjectContext.performAndWait {
  25. guard let user = record.object(in: context.managedObjectContext) else { return }
  26. cell.config(with: user)
  27. }
  28. case .placeHolder:
  29. cell.configAsPlaceHolder()
  30. }
  31. return cell
  32. }
  33. }
  34. }