diff --git a/Diary.xcodeproj/project.pbxproj b/Diary.xcodeproj/project.pbxproj index cde88a961..ce8f289e3 100644 --- a/Diary.xcodeproj/project.pbxproj +++ b/Diary.xcodeproj/project.pbxproj @@ -9,13 +9,15 @@ /* Begin PBXBuildFile section */ 459D493A878338290A3E0AEF /* Pods_Diary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDF8EB908CAD9D062C72898B /* Pods_Diary.framework */; }; 636B19AC2AA6C5E900B5242D /* AlertDisplayble.swift in Sources */ = {isa = PBXBuildFile; fileRef = 636B19AB2AA6C5E900B5242D /* AlertDisplayble.swift */; }; + 63B12BAE2AAD9C9000D614A6 /* AlertNamespace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B12BAD2AAD9C9000D614A6 /* AlertNamespace.swift */; }; + 63B12BB02AAD9D3400D614A6 /* ButtonNamespace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B12BAF2AAD9D3400D614A6 /* ButtonNamespace.swift */; }; 63BB62822A9F109400524DCB /* DecodingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63BB62812A9F109400524DCB /* DecodingManager.swift */; }; 63BB62B22AA181BE00524DCB /* Diary+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63BB62B02AA181BE00524DCB /* Diary+CoreDataClass.swift */; }; 63BB62B32AA181BE00524DCB /* Diary+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63BB62B12AA181BE00524DCB /* Diary+CoreDataProperties.swift */; }; 63BB62B52AA182AA00524DCB /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63BB62B42AA182AA00524DCB /* CoreDataManager.swift */; }; 63E527352A9D7EBF0000FBA6 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 63E527342A9D7EBF0000FBA6 /* .swiftlint.yml */; }; 63E527372A9D87660000FBA6 /* DiaryListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E527362A9D87660000FBA6 /* DiaryListTableViewCell.swift */; }; - 63E527392A9D97160000FBA6 /* CreateDiaryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E527382A9D97160000FBA6 /* CreateDiaryViewController.swift */; }; + 63E527392A9D97160000FBA6 /* DiaryDetailViewContoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63E527382A9D97160000FBA6 /* DiaryDetailViewContoller.swift */; }; BA1A55EB2A9D84AF0012C89D /* DiaryEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA1A55EA2A9D84AF0012C89D /* DiaryEntity.swift */; }; BA1A55ED2A9D90810012C89D /* DateFormatter+.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA1A55EC2A9D90810012C89D /* DateFormatter+.swift */; }; BABBDAE52A9F13A200D8D50B /* DecodingError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BABBDAE42A9F13A200D8D50B /* DecodingError.swift */; }; @@ -31,13 +33,15 @@ /* Begin PBXFileReference section */ 636B19AB2AA6C5E900B5242D /* AlertDisplayble.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertDisplayble.swift; sourceTree = ""; }; + 63B12BAD2AAD9C9000D614A6 /* AlertNamespace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertNamespace.swift; sourceTree = ""; }; + 63B12BAF2AAD9D3400D614A6 /* ButtonNamespace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonNamespace.swift; sourceTree = ""; }; 63BB62812A9F109400524DCB /* DecodingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodingManager.swift; sourceTree = ""; }; 63BB62B02AA181BE00524DCB /* Diary+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Diary+CoreDataClass.swift"; sourceTree = SOURCE_ROOT; }; 63BB62B12AA181BE00524DCB /* Diary+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Diary+CoreDataProperties.swift"; sourceTree = SOURCE_ROOT; }; 63BB62B42AA182AA00524DCB /* CoreDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = ""; }; 63E527342A9D7EBF0000FBA6 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = ""; }; 63E527362A9D87660000FBA6 /* DiaryListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryListTableViewCell.swift; sourceTree = ""; }; - 63E527382A9D97160000FBA6 /* CreateDiaryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateDiaryViewController.swift; sourceTree = ""; }; + 63E527382A9D97160000FBA6 /* DiaryDetailViewContoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryDetailViewContoller.swift; sourceTree = ""; }; 7B86D20E06F2B506DECF94F6 /* Pods-Diary.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Diary.release.xcconfig"; path = "Target Support Files/Pods-Diary/Pods-Diary.release.xcconfig"; sourceTree = ""; }; BA1A55EA2A9D84AF0012C89D /* DiaryEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryEntity.swift; sourceTree = ""; }; BA1A55EC2A9D90810012C89D /* DateFormatter+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+.swift"; sourceTree = ""; }; @@ -118,6 +122,8 @@ 63BB62B12AA181BE00524DCB /* Diary+CoreDataProperties.swift */, BA1A55EA2A9D84AF0012C89D /* DiaryEntity.swift */, 63BB62812A9F109400524DCB /* DecodingManager.swift */, + 63B12BAD2AAD9C9000D614A6 /* AlertNamespace.swift */, + 63B12BAF2AAD9D3400D614A6 /* ButtonNamespace.swift */, ); path = Model; sourceTree = ""; @@ -134,7 +140,7 @@ isa = PBXGroup; children = ( C739AE28284DF28600741E8F /* DiaryListViewController.swift */, - 63E527382A9D97160000FBA6 /* CreateDiaryViewController.swift */, + 63E527382A9D97160000FBA6 /* DiaryDetailViewContoller.swift */, ); path = Controller; sourceTree = ""; @@ -319,12 +325,14 @@ 63E527372A9D87660000FBA6 /* DiaryListTableViewCell.swift in Sources */, C739AE2F284DF28600741E8F /* Diary.xcdatamodeld in Sources */, 63BB62B52AA182AA00524DCB /* CoreDataManager.swift in Sources */, - 63E527392A9D97160000FBA6 /* CreateDiaryViewController.swift in Sources */, + 63E527392A9D97160000FBA6 /* DiaryDetailViewContoller.swift in Sources */, BABBDAE52A9F13A200D8D50B /* DecodingError.swift in Sources */, BABBDB362AAD904100D8D50B /* CoreDataError.swift in Sources */, BABBDB342AA6D05A00D8D50B /* ShareDisplayable.swift in Sources */, + 63B12BB02AAD9D3400D614A6 /* ButtonNamespace.swift in Sources */, 63BB62B32AA181BE00524DCB /* Diary+CoreDataProperties.swift in Sources */, BA1A55EB2A9D84AF0012C89D /* DiaryEntity.swift in Sources */, + 63B12BAE2AAD9C9000D614A6 /* AlertNamespace.swift in Sources */, 63BB62B22AA181BE00524DCB /* Diary+CoreDataClass.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Diary/Controller/CreateDiaryViewController.swift b/Diary/Controller/DiaryDetailViewContoller.swift similarity index 73% rename from Diary/Controller/CreateDiaryViewController.swift rename to Diary/Controller/DiaryDetailViewContoller.swift index ae2e26081..3fec1384c 100644 --- a/Diary/Controller/CreateDiaryViewController.swift +++ b/Diary/Controller/DiaryDetailViewContoller.swift @@ -1,5 +1,5 @@ // -// CreateDiaryViewController.swift +// DiaryDetailViewContoller.swift // Diary // // Created by Maxhyunm, Hamg on 2023/08/29. @@ -7,7 +7,7 @@ import UIKit -final class CreateDiaryViewController: UIViewController, AlertDisplayable, ShareDisplayable { +final class DiaryDetailViewContoller: UIViewController, AlertDisplayable, ShareDisplayable { private let textView: UITextView = { let textView = UITextView() textView.translatesAutoresizingMaskIntoConstraints = false @@ -72,7 +72,10 @@ final class CreateDiaryViewController: UIViewController, AlertDisplayable, Share } private func setupNavigationBarButton() { - let moreButton = UIBarButtonItem(title: "더보기", style: .plain, target: self, action: #selector(showMoreOptions)) + let moreButton = UIBarButtonItem(title: ButtonNamespace.more, + style: .plain, + target: self, + action: #selector(showMoreOptions)) navigationItem.rightBarButtonItem = moreButton } @@ -91,26 +94,31 @@ final class CreateDiaryViewController: UIViewController, AlertDisplayable, Share } private func showDeleteAlert() { - let cancelAction = UIAlertAction(title: "취소", style: .cancel) - let deleteAction = UIAlertAction(title: "삭제", style: .destructive) { [weak self] _ in + let cancelAction = UIAlertAction(title: ButtonNamespace.cancel, style: .cancel) + let deleteAction = UIAlertAction(title: ButtonNamespace.delete, style: .destructive) { [weak self] _ in guard let self else { return } do { try CoreDataManager.shared.deleteDiary(self.diary) self.navigationController?.popViewController(animated: true) } catch CoreDataError.deleteFailure { - let cancelAction = UIAlertAction(title: "확인", style: .cancel) + let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel) self.showAlert(title: CoreDataError.deleteFailure.alertTitle, message: CoreDataError.deleteFailure.message, - actions: [cancelAction]) + actions: [cancelAction], + preferredStyle: .alert) } catch { - let cancelAction = UIAlertAction(title: "확인", style: .cancel) + let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel) self.showAlert(title: CoreDataError.deleteFailure.alertTitle, message: CoreDataError.unknown.message, - actions: [cancelAction]) + actions: [cancelAction], + preferredStyle: .alert) } } - showAlert(title: "진짜요?", message: "정말로 삭제하시겠어요?", actions: [cancelAction, deleteAction]) + showAlert(title: AlertNamespace.deleteTitle, + message: AlertNamespace.deleteMessage, + actions: [cancelAction, deleteAction], + preferredStyle: .alert) } deinit { @@ -118,7 +126,7 @@ final class CreateDiaryViewController: UIViewController, AlertDisplayable, Share } } -extension CreateDiaryViewController { +extension DiaryDetailViewContoller { @objc private func keyboardWillShow(_ notification: Notification) { guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } @@ -129,17 +137,17 @@ extension CreateDiaryViewController { @objc private func showMoreOptions() { let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - let deleteAction = UIAlertAction(title: "Delete", style: .destructive) { [weak self] _ in + let deleteAction = UIAlertAction(title: ButtonNamespace.deleteEnglish, style: .destructive) { [weak self] _ in guard let self else { return } self.showDeleteAlert() } - let shareAction = UIAlertAction(title: "Share...", style: .default) { [weak self] _ in + let shareAction = UIAlertAction(title: ButtonNamespace.shareEnglish, style: .default) { [weak self] _ in guard let self else { return } self.shareDiary(self.diary) } - let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) + let cancelAction = UIAlertAction(title: ButtonNamespace.cancelEnglish, style: .cancel) alertController.addAction(shareAction) alertController.addAction(deleteAction) @@ -153,7 +161,7 @@ extension CreateDiaryViewController { } } -extension CreateDiaryViewController: UITextViewDelegate { +extension DiaryDetailViewContoller: UITextViewDelegate { func textViewDidEndEditing(_ textView: UITextView) { let contents = textView.text.split(separator: "\n") guard !contents.isEmpty else { return } @@ -161,15 +169,17 @@ extension CreateDiaryViewController: UITextViewDelegate { do { try CoreDataManager.shared.saveContext() } catch CoreDataError.saveFailure { - let cancelAction = UIAlertAction(title: "확인", style: .cancel) + let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel) self.showAlert(title: CoreDataError.saveFailure.alertTitle, message: CoreDataError.saveFailure.message, - actions: [cancelAction]) + actions: [cancelAction], + preferredStyle: .alert) } catch { - let cancelAction = UIAlertAction(title: "확인", style: .cancel) + let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel) self.showAlert(title: CoreDataError.saveFailure.alertTitle, message: CoreDataError.unknown.message, - actions: [cancelAction]) + actions: [cancelAction], + preferredStyle: .alert) } } diff --git a/Diary/Controller/DiaryListViewController.swift b/Diary/Controller/DiaryListViewController.swift index 57e13b51d..ba8d5b4a6 100644 --- a/Diary/Controller/DiaryListViewController.swift +++ b/Diary/Controller/DiaryListViewController.swift @@ -49,7 +49,7 @@ final class DiaryListViewController: UIViewController { private func setupNavigationBarButton() { let addDiary = UIAction(image: UIImage(systemName: "plus")) { [weak self] _ in guard let self else { return } - let createDiaryView = CreateDiaryViewController() + let createDiaryView = DiaryDetailViewContoller() self.navigationController?.pushViewController(createDiaryView, animated: true) } @@ -70,15 +70,17 @@ extension DiaryListViewController: AlertDisplayable { diaryList = fetchedDiaries.filter { $0.title != nil } tableView.reloadData() } catch CoreDataError.dataNotFound { - let cancelAction = UIAlertAction(title: "확인", style: .cancel) + let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel) showAlert(title: CoreDataError.dataNotFound.alertTitle, message: CoreDataError.dataNotFound.message, - actions: [cancelAction]) + actions: [cancelAction], + preferredStyle: .alert) } catch { - let cancelAction = UIAlertAction(title: "확인", style: .cancel) + let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel) showAlert(title: CoreDataError.dataNotFound.alertTitle, message: CoreDataError.unknown.message, - actions: [cancelAction]) + actions: [cancelAction], + preferredStyle: .alert) } } } @@ -111,7 +113,7 @@ extension DiaryListViewController: UITableViewDelegate, ShareDisplayable { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) let diaryToEdit = diaryList[indexPath.row] - let createVC = CreateDiaryViewController(diaryToEdit) + let createVC = DiaryDetailViewContoller(diaryToEdit) navigationController?.pushViewController(createVC, animated: true) } @@ -125,15 +127,17 @@ extension DiaryListViewController: UITableViewDelegate, ShareDisplayable { self.readCoreData() success(true) } catch CoreDataError.deleteFailure { - let cancelAction = UIAlertAction(title: "확인", style: .cancel) + let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel) self.showAlert(title: CoreDataError.deleteFailure.alertTitle, message: CoreDataError.deleteFailure.message, - actions: [cancelAction]) + actions: [cancelAction], + preferredStyle: .alert) } catch { - let cancelAction = UIAlertAction(title: "확인", style: .cancel) + let cancelAction = UIAlertAction(title: ButtonNamespace.confirm, style: .cancel) self.showAlert(title: CoreDataError.deleteFailure.alertTitle, message: CoreDataError.unknown.message, - actions: [cancelAction]) + actions: [cancelAction], + preferredStyle: .alert) } } diff --git a/Diary/Model/AlertNamespace.swift b/Diary/Model/AlertNamespace.swift new file mode 100644 index 000000000..2b62b5640 --- /dev/null +++ b/Diary/Model/AlertNamespace.swift @@ -0,0 +1,11 @@ +// +// AlertNamespace.swift +// Diary +// +// Created by Maxhyunm, Hamg on 2023/09/10. +// + +enum AlertNamespace { + static let deleteTitle = "진짜요?" + static let deleteMessage = "정말로 삭제하시겠어요?" +} diff --git a/Diary/Model/ButtonNamespace.swift b/Diary/Model/ButtonNamespace.swift new file mode 100644 index 000000000..9970ef396 --- /dev/null +++ b/Diary/Model/ButtonNamespace.swift @@ -0,0 +1,16 @@ +// +// ButtonNamespace.swift +// Diary +// +// Created by Maxhyunm, Hamg on 2023/09/10. +// + +enum ButtonNamespace { + static let more = "더보기" + static let cancel = "취소" + static let delete = "삭제" + static let confirm = "확인" + static let deleteEnglish = "Delete" + static let shareEnglish = "Share..." + static let cancelEnglish = "Cancel" +} diff --git a/Diary/Protocol/AlertDisplayble.swift b/Diary/Protocol/AlertDisplayble.swift index 942ecc0b1..5f4e37282 100644 --- a/Diary/Protocol/AlertDisplayble.swift +++ b/Diary/Protocol/AlertDisplayble.swift @@ -8,12 +8,15 @@ import UIKit protocol AlertDisplayable { - func showAlert(title: String?, message: String?, actions: [UIAlertAction]) + func showAlert(title: String?, message: String?, actions: [UIAlertAction], preferredStyle: UIAlertController.Style) } extension AlertDisplayable where Self: UIViewController { - func showAlert(title: String?, message: String?, actions: [UIAlertAction]) { - let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) + func showAlert(title: String?, + message: String?, + actions: [UIAlertAction], + preferredStyle: UIAlertController.Style) { + let alertController = UIAlertController(title: title, message: message, preferredStyle: preferredStyle) actions.forEach { alertController.addAction($0) } present(alertController, animated: true)