From 82e16f0bb7d600bc7b892441e514af98ee8ef502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B2=BD=EB=AF=BC?= <74659491+meenyweeny@users.noreply.github.com> Date: Fri, 29 Jul 2022 23:57:26 +0900 Subject: [PATCH] =?UTF-8?q?[#142]=20weak=20self=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/CheckMessageViewController.swift | 6 +++--- .../Controller/CheckTimeTravelViewController.swift | 8 ++++---- .../CheckTimeTravelDetailViewController.swift | 12 ++++++------ .../Screen/Main/Controller/MainViewController.swift | 10 +++------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Deartoday/Deartoday/Screen/CheckMessage/Controller/CheckMessageViewController.swift b/Deartoday/Deartoday/Screen/CheckMessage/Controller/CheckMessageViewController.swift index f022c45..c64bb33 100644 --- a/Deartoday/Deartoday/Screen/CheckMessage/Controller/CheckMessageViewController.swift +++ b/Deartoday/Deartoday/Screen/CheckMessage/Controller/CheckMessageViewController.swift @@ -151,9 +151,9 @@ extension CheckMessageViewController: UICollectionViewDelegate { extension CheckMessageViewController { private func getMessageInfo() { - CheckMessageAPI.shared.getCheckMessage { response in - guard let responseData = response else { return } - self.setMessageInfo(response: responseData.data?.lastAnswer ?? []) + CheckMessageAPI.shared.getCheckMessage { [weak self] messageData in + guard let messageData = messageData else { return } + self?.setMessageInfo(response: messageData.data?.lastAnswer ?? []) } } } diff --git a/Deartoday/Deartoday/Screen/CheckTimeTravel/Controller/CheckTimeTravelViewController.swift b/Deartoday/Deartoday/Screen/CheckTimeTravel/Controller/CheckTimeTravelViewController.swift index e190e11..7c5cb3c 100644 --- a/Deartoday/Deartoday/Screen/CheckTimeTravel/Controller/CheckTimeTravelViewController.swift +++ b/Deartoday/Deartoday/Screen/CheckTimeTravel/Controller/CheckTimeTravelViewController.swift @@ -133,10 +133,10 @@ extension CheckTimeTravelViewController: UITableViewDelegate { extension CheckTimeTravelViewController { private func getTimeTravelInfo() { - CheckTimeTravelAPI.shared.getCheckTimeTravel { response in - guard let responseData = response else { return } - self.timeTapes = responseData.data?.timeTravels ?? [] - self.setTimeTravelTapeInfo() + CheckTimeTravelAPI.shared.getCheckTimeTravel { [weak self] tapeData in + guard let tapeData = tapeData else { return } + self?.timeTapes = tapeData.data?.timeTravels ?? [] + self?.setTimeTravelTapeInfo() } } } diff --git a/Deartoday/Deartoday/Screen/CheckTimeTravelDetail/Controller/CheckTimeTravelDetailViewController.swift b/Deartoday/Deartoday/Screen/CheckTimeTravelDetail/Controller/CheckTimeTravelDetailViewController.swift index 31d847b..f740801 100644 --- a/Deartoday/Deartoday/Screen/CheckTimeTravelDetail/Controller/CheckTimeTravelDetailViewController.swift +++ b/Deartoday/Deartoday/Screen/CheckTimeTravelDetail/Controller/CheckTimeTravelDetailViewController.swift @@ -186,12 +186,12 @@ extension CheckTimeTravelDetailViewController: UICollectionViewDelegateFlowLayou // MARK: - Network extension CheckTimeTravelDetailViewController { - func getTravelInfo(timeTravelId: String) { - CheckTimeTravelAPI.shared.getTimeTravelDetail(timeTravelId: timeTravelId) { response in - guard let info = response?.data as? CheckTimeTravelDetailResponse else { return } - self.travelInfo = info - self.dialogs = info.messages - self.collectionView.reloadData() + private func getTravelInfo(timeTravelId: String) { + CheckTimeTravelAPI.shared.getTimeTravelDetail(timeTravelId: timeTravelId) { [weak self] travelData in + guard let travelData = travelData?.data as? CheckTimeTravelDetailResponse else { return } + self?.travelInfo = travelData + self?.dialogs = travelData.messages + self?.collectionView.reloadData() } } } diff --git a/Deartoday/Deartoday/Screen/Main/Controller/MainViewController.swift b/Deartoday/Deartoday/Screen/Main/Controller/MainViewController.swift index 16a79c8..fc88d53 100644 --- a/Deartoday/Deartoday/Screen/Main/Controller/MainViewController.swift +++ b/Deartoday/Deartoday/Screen/Main/Controller/MainViewController.swift @@ -33,7 +33,7 @@ final class MainViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() setUI() - setData() + setDate() setDelegate() setGesture() setBackSwipeGesture() @@ -54,10 +54,6 @@ final class MainViewController: UIViewController { setLayout() } - private func setData() { - setDate() - } - private func setDelegate() { backgroundScrollView.delegate = self } @@ -144,9 +140,9 @@ extension MainViewController: UIScrollViewDelegate { extension MainViewController { private func getMainData() { - MainAPI.shared.getMain { mainData in + MainAPI.shared.getMain { [weak self] mainData in guard let mainData = mainData else { return } - self.setCountLabel(count: mainData.data?.timeTravelCount ?? 0) + self?.setCountLabel(count: mainData.data?.timeTravelCount ?? 0) } } }