diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/View/CustomAlbumCollectionViewCell.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/View/CustomAlbumCollectionViewCell.swift index 98c0969e..d0b6d869 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/View/CustomAlbumCollectionViewCell.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/View/CustomAlbumCollectionViewCell.swift @@ -43,7 +43,7 @@ final class CustomAlbumCollectionViewCell: UICollectionViewCell { } // MARK: - Set Cell Image - func setPhoto(_ photo: UIImage?) { + func setPhoto(_ photo: UIImage?) async { photoImageView.image = photo } } diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/View/CustomAlbumViewController.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/View/CustomAlbumViewController.swift index 6379624a..c6cc156f 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/View/CustomAlbumViewController.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/View/CustomAlbumViewController.swift @@ -72,15 +72,19 @@ extension CustomAlbumViewController: UICollectionViewDelegate { _ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath ) { - if indexPath.item == 0 { - self.openCamera() - } else { - guard let asset = viewModel.photoAsset?[indexPath.item - 1] else { return } - LocalPhotoManager.shared.requestIamge(with: asset) { [weak self] image in - guard let self else { return } - let editViewController = EditPhotoViewController() - editViewController.setPhoto(image: image) - self.navigationController?.pushViewController(editViewController, animated: true) + Task { + if indexPath.item == 0 { + self.openCamera() + } else { + guard let asset = viewModel.photoAsset?[indexPath.item - 1] else { return } + await LocalPhotoManager.shared.requestImage(with: asset) { @Sendable [weak self] image in + guard let self else { return } + Task { + let editViewController = await EditPhotoViewController() + await editViewController.setPhoto(image: image) + await self.navigationController?.pushViewController(editViewController, animated: true) + } + } } } } @@ -105,16 +109,20 @@ extension CustomAlbumViewController: UICollectionViewDataSource { for: indexPath ) as? CustomAlbumCollectionViewCell else { return UICollectionViewCell() } - if indexPath.item == 0 { - cell.setPhoto(.photo) - } else { - guard let asset = viewModel.photoAsset?[indexPath.item - 1] else { return cell } - let cellSize = cell.bounds.size - LocalPhotoManager.shared.requestIamge(with: asset, cellSize: cellSize) { image in - cell.setPhoto(image) + Task { + if indexPath.item == 0 { + await cell.setPhoto(.photo) + } else { + guard let asset = viewModel.photoAsset?[indexPath.item - 1] else { return cell } + let cellSize = cell.bounds.size + await LocalPhotoManager.shared.requestImage(with: asset, cellSize: cellSize) { @Sendable image in + Task { + await cell.setPhoto(image) + } + } } + return cell } - return cell } } diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/ViewModel/LocalPhotoManager.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/ViewModel/LocalPhotoManager.swift index bce97742..074e5c7c 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/ViewModel/LocalPhotoManager.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/ViewModel/LocalPhotoManager.swift @@ -14,7 +14,7 @@ actor LocalPhotoManager { private init() { } - func requestIamge(with asset: PHAsset?, cellSize: CGSize = .zero, completion: @escaping (UIImage?) -> Void) { + func requestImage(with asset: PHAsset?, cellSize: CGSize = .zero, completion: @escaping (UIImage?) -> Void) { guard let asset else { return } imageManager.requestImage( diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/EditPhoto/EditPhotoViewController.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/EditPhoto/EditPhotoViewController.swift index 84fb6813..73adb616 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/EditPhoto/EditPhotoViewController.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/EditPhoto/EditPhotoViewController.swift @@ -1,5 +1,6 @@ import UIKit +@MainActor public final class EditPhotoViewController: UIViewController { // MARK: - Properties private let clearView = UIView.dimmedView(opacity: 0)