From 9ad70b9a9a43eae7e4838b38903e39da3e06ab64 Mon Sep 17 00:00:00 2001 From: k2645 Date: Tue, 12 Nov 2024 01:40:04 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20actor=20=EA=B4=80=EB=A0=A8=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - EditPhotoViewController @MainActor 키워드 추가 - CustomAlbumViewController 내부 async 함수 처리를 위한 Task 코드 블럭 추가 - CustomAlbumCollectionViewCell의 이미지 설정 메서드 async 처리 --- .../View/CustomAlbumCollectionViewCell.swift | 2 +- .../View/CustomAlbumViewController.swift | 42 +++++++++++-------- .../ViewModel/LocalPhotoManager.swift | 2 +- .../EditPhoto/EditPhotoViewController.swift | 1 + 4 files changed, 28 insertions(+), 19 deletions(-) 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)