From e9a475c0d356a28b41d6572af88c44eed33f5353 Mon Sep 17 00:00:00 2001 From: hemg2 Date: Tue, 5 Sep 2023 15:41:31 +0900 Subject: [PATCH] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EC=88=98=EC=A0=95=20=EC=A7=84=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Diary/Controller/CreateDiaryViewController.swift | 14 +++++++------- Diary/Controller/DiaryListViewController.swift | 16 ++++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Diary/Controller/CreateDiaryViewController.swift b/Diary/Controller/CreateDiaryViewController.swift index 9a752d6f2..98320985e 100644 --- a/Diary/Controller/CreateDiaryViewController.swift +++ b/Diary/Controller/CreateDiaryViewController.swift @@ -15,10 +15,10 @@ final class CreateDiaryViewController: UIViewController, AlertDisplayable, Share return textView }() - + private let container = CoreDataManager.shared.persistentContainer - var diary: Diary - var isNew: Bool + private var diary: Diary + private var isNew: Bool init() { self.diary = CoreDataManager.shared.createDiary() @@ -43,7 +43,7 @@ final class CreateDiaryViewController: UIViewController, AlertDisplayable, Share setupNavigationBarButton() setupNotification() } - + private func configureUI() { view.backgroundColor = .systemBackground self.title = DateFormatter().formatToString(from: Date(), with: "YYYY년 MM월 dd일") @@ -75,7 +75,7 @@ final class CreateDiaryViewController: UIViewController, AlertDisplayable, Share let moreButton = UIBarButtonItem(title: "더보기", style: .plain, target: self, action: #selector(showMoreOptions)) navigationItem.rightBarButtonItem = moreButton } - + private func setupNotification() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), @@ -94,13 +94,13 @@ final class CreateDiaryViewController: UIViewController, AlertDisplayable, Share let cancelAction = UIAlertAction(title: "취소", style: .cancel) let deleteAction = UIAlertAction(title: "삭제", style: .destructive) { [weak self] _ in guard let self else { return } - CoreDataManager.shared.deleteDiary(diary) + CoreDataManager.shared.deleteDiary(self.diary) self.navigationController?.popViewController(animated: true) } showAlert(title: "진짜요?", message: "정말로 삭제하시겠어요?", actions: [cancelAction, deleteAction]) } - + deinit { NotificationCenter.default.removeObserver(self) } diff --git a/Diary/Controller/DiaryListViewController.swift b/Diary/Controller/DiaryListViewController.swift index b4b46acf4..06b77cd82 100644 --- a/Diary/Controller/DiaryListViewController.swift +++ b/Diary/Controller/DiaryListViewController.swift @@ -6,7 +6,7 @@ import UIKit -final class DiaryListViewController: UIViewController, AlertDisplayable, ShareDiary { +final class DiaryListViewController: UIViewController { private let tableView: UITableView = { let tableView = UITableView() tableView.translatesAutoresizingMaskIntoConstraints = false @@ -20,7 +20,7 @@ final class DiaryListViewController: UIViewController, AlertDisplayable, ShareDi override func viewDidLoad() { super.viewDidLoad() - + configureUI() setupNavigationBarButton() setupTableView() @@ -61,7 +61,9 @@ final class DiaryListViewController: UIViewController, AlertDisplayable, ShareDi tableView.delegate = self tableView.register(DiaryListTableViewCell.self, forCellReuseIdentifier: DiaryListTableViewCell.identifier) } - +} + +extension DiaryListViewController: AlertDisplayable { private func readCoreData() { do { let fetchedDiaries = try container.viewContext.fetch(Diary.fetchRequest()) @@ -74,7 +76,7 @@ final class DiaryListViewController: UIViewController, AlertDisplayable, ShareDi } } -extension DiaryListViewController: UITableViewDataSource, UITableViewDelegate { +extension DiaryListViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { diaryList.count } @@ -94,12 +96,14 @@ extension DiaryListViewController: UITableViewDataSource, UITableViewDelegate { return cell } - +} + +extension DiaryListViewController: UITableViewDelegate, ShareDiary { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) let diaryToEdit = diaryList[indexPath.row] let createVC = CreateDiaryViewController(diaryToEdit) - + navigationController?.pushViewController(createVC, animated: true) }