Skip to content

Commit

Permalink
fix: actor 관련 에러 수정
Browse files Browse the repository at this point in the history
- EditPhotoViewController @mainactor 키워드 추가
- CustomAlbumViewController 내부 async 함수 처리를 위한 Task 코드 블럭 추가
- CustomAlbumCollectionViewCell의 이미지 설정 메서드 async 처리
  • Loading branch information
k2645 committed Nov 11, 2024
1 parent 8b1fabb commit 9ad70b9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class CustomAlbumCollectionViewCell: UICollectionViewCell {
}

// MARK: - Set Cell Image
func setPhoto(_ photo: UIImage?) {
func setPhoto(_ photo: UIImage?) async {
photoImageView.image = photo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
}
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit

@MainActor
public final class EditPhotoViewController: UIViewController {
// MARK: - Properties
private let clearView = UIView.dimmedView(opacity: 0)
Expand Down

0 comments on commit 9ad70b9

Please sign in to comment.