Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ final class CalendarCardCVC: UICollectionViewCell {

override func prepareForReuse() {
super.prepareForReuse()
self.cancelBag.cancel()
self.cancelBag = CancelBag()
resetSubscription()
}
}

Expand Down Expand Up @@ -144,4 +143,9 @@ extension CalendarCardCVC {
}
self.attendanceButton.isHidden = (userType == .visitor || userType == .inactive)
}

func resetSubscription() {
self.cancelBag.cancel()
self.cancelBag = CancelBag()
}
Comment on lines +148 to +151
Copy link
Member

Choose a reason for hiding this comment

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

함수로 분리해주신 것 좋네요!

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ final class HomeForMemberVC: UIViewController, HomeForMemberViewControllable {
stopLatestPostAnimationLoop()
cancelTasks()
stopPopularPostsAnimationLoop()
resetCellSubscription()
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

구독 정리 로직이 올바르게 구현되었습니다.

뷰 컨트롤러가 사라질 때 캘린더 셀의 구독을 정리하는 로직이 적절히 추가되었습니다. 이전 리뷰에서 지적된 메서드명 불일치 문제도 해결되었습니다.

참고: PR 설명에는 viewWillDisappear에서 구독을 reset한다고 명시되어 있으나, 실제 구현은 viewDidDisappear를 사용하고 있습니다. 두 메서드 모두 정리 작업에 적합하지만, 문서와 코드 간 일관성을 위해 PR 설명을 업데이트하는 것을 권장합니다.

🤖 Prompt for AI Agents
In
SOPT-iOS/Projects/Features/HomeFeature/Sources/HomeScene/VC/HomeForMemberVC.swift
around line 91, the subscription reset is implemented in viewDidDisappear
(resetCellSubscription()) but the PR description states it runs in
viewWillDisappear; update the PR description to state that subscriptions are
reset in viewDidDisappear to keep docs consistent with code, or if you prefer
the cleanup to happen earlier change the implementation to call
resetCellSubscription() from viewWillDisappear instead and ensure method naming
and lifecycle choice are documented accordingly.

}
}

Expand Down Expand Up @@ -382,6 +383,12 @@ extension HomeForMemberVC {
}
}
}

private func resetCellSubscription() {
collectionView.visibleCells
.compactMap { $0 as? CalendarCardCVC }
.forEach { $0.resetSubscription() }
}
}
Copy link
Member

@yungu0010 yungu0010 Oct 19, 2025

Choose a reason for hiding this comment

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

여기보단 HomeForMemberCellProvider의 메소드 내에서 cell.cancelBag.cancel()을 호출하는 것이 로직상 더 자연스러울 것 같아요.

🌱 제안 이유

CalendarCardCVCprepareForReuse()에서 구독을 초기화하고 있기 때문에, 스크롤되지 않는 상황에서는 구독이 해제되지 않는 것이 원인으로 보여요.

📌 의문점

여기서 한 가지 궁금했던 부분이 있었는데요. HomeForMemberVC에서 사용하는 다른 셀들(DefaultPostCVC, HomeDefaultHeaderView)도 똑같이 prepareForReuse()에서 구독을 초기화해주고 있는데, 왜 이 셀들은 스크롤하지 않아도 문제가 없었는지 의문이 들었습니다.

코드를 살펴보니 setItemsNeedUpdate()의 동작 차이가 원인이었던 것으로 보여요.

CalendarCVC의 경우

  1. setItemsNeedUpdate 호출마다 갱신
  2. 그 때마다 createCalendarCellRegistration() 클로저가 다시 실행
  3. 해당 메소드 내에서 새로운 구독이 cell.cancelBag에 추가
  4. 스크롤이 없는 경우 prepareForReuse()가 호출되지 않음
  5. cancelBag이 초기화되지 않은 채로 구독이 쌓이는 문제 발생

HomeDefaultHeaderView와 DefaultPostCVC

  1. setItemsNeedUpdate 에서 갱신하지 않음
  2. Provider의 메소드가 재호출되지 않음
  3. 구독이 그대로 유지
  4. 스크롤하지 않았을 때 구독 해제 되지 않는 것은 같음

📝 제안 방안

그래서 이 부분보다는 createCalendarCellRegistration() 메소드에서 cell.cancelBag.cancel()을 먼저 해주는 것이 더 적절하다고 생각합니다.

func createCalendarCellRegistration() -> CalendarCellRegistration {
    collectionView.createCellRegistration { [weak self] cell, _, item in
        guard let self else { return }
        
        // 새 구독 추가 전에 기존 구독 정리
        cell.cancelBag.cancel()
        
        // 이후 설정 진행...
    }
}

또한 VC에서 타입 캐스팅을 통해 특정 셀의 구독을 관리하는 것보다 셀을 설정하는 메소드에서 구독을 초기화하는 것이 흐름상으로도 더 자연스럽다고 생각해요!

저도 미처 발견하지 못했던 부분인데 덕분에 알고 갑니다👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

우와 !! diffable data source를 사용해본 적이 없어서 cell 관리를 어떻게 해주는지 제대로 파악하지 못한 것 같네요 !!!!
덕분에 공부도 하고 많이 배워갑니다 !!!!!!


// MARK: - UICollectionViewDelegate
Expand Down