Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] UploadCodyViewController를 dismiss할 때 메모리가 해제되지 않는 현상 개선 #21

Merged
merged 5 commits into from
Feb 1, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ private extension UploadCodyCoordinator {
extension UploadCodyCoordinator: UploadCodyCoordinatorInterface {
func dismissUploadCody(_ viewController: UIViewController) {
finishDelegate?.coordinatorDidFinish(childCoordinator: self)
viewController.dismiss(animated: true)
}

func showAlbum() {
Expand Down
26 changes: 22 additions & 4 deletions Fitfty/Projects/Coordinator/Sources/TabCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ final class TabCoordinator: NSObject, Coordinator, TabCoordinatorProtocol {
switch page {
case .weather:
let coordinator = MainCoordinator()
childCoordinators.append(coordinator)
coordinator.start()
let tabBarItem = UITabBarItem.init(
title: nil,
Expand All @@ -114,19 +115,19 @@ final class TabCoordinator: NSObject, Coordinator, TabCoordinatorProtocol {
tabBarController.addChild(coordinator.navigationController)

case .createCody:
let coordinator = UploadCodyCoordinator()
coordinator.start()
let dummyController = UINavigationController()
let tabBarItem = UITabBarItem.init(
title: nil,
image: page.pageIconImage,
tag: page.pageOrderNumber
)
coordinator.navigationController.tabBarItem = tabBarItem
dummyController.tabBarItem = tabBarItem
tabBarItem.imageInsets = UIEdgeInsets(top: 13, left: 0, bottom: -15, right: 0)
tabBarController.addChild(coordinator.navigationController)
tabBarController.addChild(dummyController)
Comment on lines 117 to +126
Copy link
Member Author

@leeari95 leeari95 Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 코디네이터를 등록해도 실제로는 사용되지 않고 있기 때문에,
불필요한 메모리를 추가한다는 생각이 들어서
수정해서 개선해주었어요.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵넵 최고최고!!


case .profile:
let coordinator = ProfileCoordinator()
childCoordinators.append(coordinator)
coordinator.start()
let tabBarItem = UITabBarItem.init(
title: nil,
Expand Down Expand Up @@ -170,6 +171,9 @@ extension TabCoordinator: UITabBarControllerDelegate {
}
if tabBar == .createCody {
let coordinator = UploadCodyCoordinator()
childCoordinators.append(coordinator)
coordinator.finishDelegate = self
coordinator.parentCoordinator = self
coordinator.start()
coordinator.navigationController.modalPresentationStyle = .fullScreen
tabBarController.present(coordinator.navigationController, animated: true)
Expand Down Expand Up @@ -197,3 +201,17 @@ extension TabCoordinator: UITabBarControllerDelegate {
}

}

extension TabCoordinator: CoordinatorFinishDelegate {

func coordinatorDidFinish(childCoordinator: Coordinator) {
childDidFinish(childCoordinator, parent: self)
switch childCoordinator.type {
case .uploadCody:
tabBarController.dismiss(animated: true) {
childCoordinator.navigationController.viewControllers.removeAll()
}
default: break
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public final class WeatherViewController: UIViewController {
fatalError("init(coder:) has not been implemented")
}

deinit {
coordinator.finished()
}

private lazy var locationView: LocationView = {
let locationView = LocationView("성북구 정릉동")
let tappedLoacationView = UITapGestureRecognizer(target: self, action: #selector(didTapLoactionView(_:)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ final public class AlbumViewController: UIViewController {
cell?.setImage(image: image)
}
}
return cell
return cell ?? UICollectionViewCell()
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ extension UploadCodyViewController {
private func setUpDataSource() {
dataSource = UICollectionViewDiffableDataSource<Section, UUID>(
collectionView: collectionView,
cellProvider: { collectionView, indexPath, _ in
cellProvider: { [weak self] collectionView, indexPath, _ in
guard let self = self else {
return UICollectionViewCell()
}
let section = Section(index: indexPath.section)
switch section {
case .content:
Expand Down Expand Up @@ -457,15 +460,15 @@ extension UploadCodyViewController: UICollectionViewDelegate {
// MARK: - AlbumAuthorization
extension UploadCodyViewController {
@objc private func didTapUploadPhotoButton(_ sender: UIButton) {
self.requestAlbumAuthorization { isAuthorized in
requestAlbumAuthorization { [weak self] isAuthorized in
if isAuthorized {
PhotoService.shared.getAlbums(completion: { [weak self] _ in
DispatchQueue.main.async {
self?.coordinator.showAlbum()
}
})
} else {
self.showAlertGoToSetting(
self?.showAlertGoToSetting(
title: "현재 앨범 사용에 대한 접근 권한이 없습니다.",
message: "설정 > 핏프티 탭에서 접근을 활성화 할 수 있습니다."
)
Expand Down Expand Up @@ -508,8 +511,8 @@ extension UploadCodyViewController {
}
[cancelAlert, goToSettingAlert]
.forEach(alertController.addAction(_:))
DispatchQueue.main.async {
self.present(alertController, animated: true)
DispatchQueue.main.async { [weak self] in
self?.present(alertController, animated: true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public final class SettingViewController: UIViewController {
fatalError("init(coder:) has not been implemented")
}

deinit {
coordinator?.finished()
}

private lazy var collectionView: UICollectionView = {
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: createLayout())
collectionView.register(SettingCell.self)
Expand Down