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) }