From 6a8e2e42efbb5a75b9a33200c34c71a5fb39bcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AF=BC=EC=A4=80?= <132960058+aado97@users.noreply.github.com> Date: Mon, 10 Feb 2025 17:46:39 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[#13]=201=EC=B0=A8=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81=20MVVM=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project.pbxproj" | 34 +++++- .../Model/Reflection.swift" | 13 +++ .../View/main.swift" | 66 ++++++++++++ .../ViewModel/ReflectionViewModel.swift" | 53 ++++++++++ .../main.swift" | 100 ------------------ 5 files changed, 165 insertions(+), 101 deletions(-) create mode 100644 "dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" create mode 100644 "dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" create mode 100644 "dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" delete mode 100644 "dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/main.swift" diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234.xcodeproj/project.pbxproj" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234.xcodeproj/project.pbxproj" index 41d8759..d00500b 100644 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234.xcodeproj/project.pbxproj" +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234.xcodeproj/project.pbxproj" @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 5957EFEA2D59D0700019B873 /* Reflection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5957EFE92D59D0700019B873 /* Reflection.swift */; }; + 5957EFEC2D59D1550019B873 /* ReflectionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5957EFEB2D59D1550019B873 /* ReflectionViewModel.swift */; }; 598907C92D461A930024CCEF /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 598907C82D461A930024CCEF /* main.swift */; }; /* End PBXBuildFile section */ @@ -23,6 +25,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 5957EFE92D59D0700019B873 /* Reflection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reflection.swift; sourceTree = ""; }; + 5957EFEB2D59D1550019B873 /* ReflectionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReflectionViewModel.swift; sourceTree = ""; }; 598907C52D461A930024CCEF /* Weekly01_회고시스템 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Weekly01_회고시스템"; sourceTree = BUILT_PRODUCTS_DIR; }; 598907C82D461A930024CCEF /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -38,6 +42,30 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 5957EFE62D59CAAD0019B873 /* ViewModel */ = { + isa = PBXGroup; + children = ( + 5957EFEB2D59D1550019B873 /* ReflectionViewModel.swift */, + ); + path = ViewModel; + sourceTree = ""; + }; + 5957EFE72D59CAB90019B873 /* View */ = { + isa = PBXGroup; + children = ( + 598907C82D461A930024CCEF /* main.swift */, + ); + path = View; + sourceTree = ""; + }; + 5957EFE82D59CABF0019B873 /* Model */ = { + isa = PBXGroup; + children = ( + 5957EFE92D59D0700019B873 /* Reflection.swift */, + ); + path = Model; + sourceTree = ""; + }; 598907BC2D461A930024CCEF = { isa = PBXGroup; children = ( @@ -57,7 +85,9 @@ 598907C72D461A930024CCEF /* Weekly01_회고시스템 */ = { isa = PBXGroup; children = ( - 598907C82D461A930024CCEF /* main.swift */, + 5957EFE82D59CABF0019B873 /* Model */, + 5957EFE72D59CAB90019B873 /* View */, + 5957EFE62D59CAAD0019B873 /* ViewModel */, ); path = "Weekly01_회고시스템"; sourceTree = ""; @@ -120,6 +150,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5957EFEA2D59D0700019B873 /* Reflection.swift in Sources */, + 5957EFEC2D59D1550019B873 /* ReflectionViewModel.swift in Sources */, 598907C92D461A930024CCEF /* main.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" new file mode 100644 index 0000000..7fdf702 --- /dev/null +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" @@ -0,0 +1,13 @@ +// +// Reflection.swift +// Weekly01_회고시스템 +// +// Created by 도민준 on 2/10/25. +// + +import Foundation + +struct Reflection { + let date: String + var content: String +} diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" new file mode 100644 index 0000000..1ca0dde --- /dev/null +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" @@ -0,0 +1,66 @@ +// +// main.swift +// Weekly01_회고시스템 +// +// Created by 도민준 on 1/26/25. +// + +import Foundation + +var reflectionManager = ReflectionViewModel() +var menuNum = 0 +var date = "" +var content = "" + +print(""" +=== 회고 시스템 === +1. 회고 추가 +2. 회고 조회 +3. 회고 수정 +4. 회고 삭제 +5. 전체 회고 목록 출력 +6. 종료 +""") +print() + +while true { + print("메뉴를 선택하세요:", terminator: " ") + + menuNum = Int(readLine() ?? "0") ?? 0 + + if menuNum == 6 { + print("프로그램을 종료합니다.") + break + } + + switch menuNum { + case 1: + print("날짜를 입력하세요 (예: 2024-12-25):", terminator: " ") + date = readLine() ?? "" + print("회고 내용을 입력하세요:", terminator: " ") + content = readLine() ?? "" + reflectionManager.addReflection(date: date, content: content) + //replections[date] = content + //print(replections) + + case 2: + print("조회할 날짜를 입력하세요:", terminator: " ") + date = readLine() ?? "" + reflectionManager.retrieveReflection(date: date) + case 3: + print("수정할 날짜를 입력하세요:", terminator: " ") + date = readLine() ?? "" + reflectionManager.updateReflection(date: date) + case 4: + print("삭제할 날짜를 입력하세요:", terminator: " ") + date = readLine() ?? "" + reflectionManager.deleteReflection(date: date) + + case 5: + reflectionManager.printAllReflection() + default: + print("잘못된 입력입니다.") + print() + } +} + diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" new file mode 100644 index 0000000..481b232 --- /dev/null +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" @@ -0,0 +1,53 @@ +// +// ReflectionViewModel.swift +// Weekly01_회고시스템 +// +// Created by 도민준 on 2/10/25. +// + +import Foundation + +class ReflectionViewModel { + private var reflections: [String: Reflection] = [:] + + func addReflection(date: String, content: String) { + reflections[date] = Reflection(date: date, content: content) + print("회고가 추가 되었습니다.\n") + } + + func retrieveReflection(date: String) { + if let reflection = reflections[date] { + print("날짜: \(reflection.date)") + print("내용: \(reflection.content)\n") + } else { + print("해당 날짜의 회고가 없습니다.\n") + } + } + + func updateReflection(date: String) { + if reflections[date] != nil { + print("새로운 회고 내용을 입력하세요: ", terminator: " ") + var newContent = readLine() ?? "" + reflections[date]?.content = newContent + print("회고가 수정되었습니다.\n") + } else { + print("해당 날짜의 회고가 없습니다.\n") + } + } + + func deleteReflection(date: String) { + if reflections.removeValue(forKey: date) != nil { + print("회고가 삭제되었습니다.\n") + } else { + print("해당 날짜의 회고가 없습니다.\n") + } + } + + func printAllReflection() { + print("=== 저장된 회고 목록 ===") + for reflection in reflections.values { + print("날짜: \(reflection.date)") + print("내용: \(reflection.content)") + } + } +} diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/main.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/main.swift" deleted file mode 100644 index 8b16201..0000000 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/main.swift" +++ /dev/null @@ -1,100 +0,0 @@ -// -// main.swift -// Weekly01_회고시스템 -// -// Created by 도민준 on 1/26/25. -// - -import Foundation - -var menuNum = 0 -var replections: [String: String] = [:] -var date = "" -var content = "" -var dateArray: [String] = [] -var contentArray: [String] = [] - -print(""" -=== 회고 시스템 === -1. 회고 추가 -2. 회고 조회 -3. 회고 수정 -4. 회고 삭제 -5. 전체 회고 목록 출력 -6. 종료 -""") -print() - -while true { - print("메뉴를 선택하세요:", terminator: " ") - - menuNum = Int(readLine() ?? "0") ?? 0 - - if menuNum == 6 { - print("프로그램을 종료합니다.") - break - } - - switch menuNum { - case 1: - print("날짜를 입력하세요 (예: 2024-12-25):", terminator: " ") - date = readLine() ?? "" - print("회고 내용을 입력하세요:", terminator: " ") - content = readLine() ?? "" - replections[date] = content - //print(replections) - print("회고가 추가 되었습니다.") - print() - case 2: - print("조회할 날짜를 입력하세요:", terminator: " ") - date = readLine() ?? "" - if let contentOfDate = replections[date] { - print("날짜: \(date)") - print("내용: \(contentOfDate)") - print() - } else { - print("해당 날짜의 회고가 없습니다.") - print() - } - case 3: - print("수정할 날짜를 입력하세요:", terminator: " ") - date = readLine() ?? "" - if let contentOfDate = replections[date] { - print("새로운 회고 내용을 입력하세요: ", terminator: " ") - content = readLine() ?? "" - replections[date] = content - //print(replections) - print("회고가 수정되었습니다.") - print() - } else { - print("해당 날짜의 회고가 없습니다.") - print() - } - case 4: - print("삭제할 날짜를 입력하세요:", terminator: " ") - date = readLine() ?? "" - if let contentOfDate = replections[date] { - //print(replections) - replections.removeValue(forKey: date) - //print(replections) - print("회고가 삭제되었습니다.") - print() - } else { - print("해당 날짜의 회고가 없습니다.") - print() - } - case 5: - print("=== 저장된 회고 목록 ===") - dateArray = Array(replections.keys) - contentArray = Array(replections.values) - for i in 0 ..< replections.count { - print("날짜: \(dateArray[i])") - print("내용: \(contentArray[i])") - print() - } - default: - print("잘못된 입력입니다.") - print() - } -} - From adfb0d27e29b8c8c91dd2b3e9626ab2a11f32f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AF=BC=EC=A4=80?= <132960058+aado97@users.noreply.github.com> Date: Tue, 11 Feb 2025 20:54:05 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[#13]=20=20=EC=A3=BC=EC=84=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/main.swift" | 16 ++------------- .../ViewModel/ReflectionViewModel.swift" | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" index 1ca0dde..b9b4bb7 100644 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" @@ -12,16 +12,7 @@ var menuNum = 0 var date = "" var content = "" -print(""" -=== 회고 시스템 === -1. 회고 추가 -2. 회고 조회 -3. 회고 수정 -4. 회고 삭제 -5. 전체 회고 목록 출력 -6. 종료 -""") -print() +reflectionManager.printMenu() while true { print("메뉴를 선택하세요:", terminator: " ") @@ -40,8 +31,6 @@ while true { print("회고 내용을 입력하세요:", terminator: " ") content = readLine() ?? "" reflectionManager.addReflection(date: date, content: content) - //replections[date] = content - //print(replections) case 2: print("조회할 날짜를 입력하세요:", terminator: " ") @@ -59,8 +48,7 @@ while true { case 5: reflectionManager.printAllReflection() default: - print("잘못된 입력입니다.") - print() + print("잘못된 입력입니다.\n") } } diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" index 481b232..fb9164a 100644 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" @@ -8,13 +8,30 @@ import Foundation class ReflectionViewModel { + //날짜를 키 값으로 정하기 위해 + //private 메서드를 통해서만 접근 가능하게 하여 데이터 무결성 유지 private var reflections: [String: Reflection] = [:] + // 메뉴 출력 + func printMenu() { + print(""" + === 회고 시스템 === + 1. 회고 추가 + 2. 회고 조회 + 3. 회고 수정 + 4. 회고 삭제 + 5. 전체 회고 목록 출력 + 6. 종료\n + """) + } + + // 회고 추가 func addReflection(date: String, content: String) { reflections[date] = Reflection(date: date, content: content) print("회고가 추가 되었습니다.\n") } + // 회고 조회 func retrieveReflection(date: String) { if let reflection = reflections[date] { print("날짜: \(reflection.date)") @@ -24,6 +41,7 @@ class ReflectionViewModel { } } + // 회고 수정 func updateReflection(date: String) { if reflections[date] != nil { print("새로운 회고 내용을 입력하세요: ", terminator: " ") @@ -35,6 +53,7 @@ class ReflectionViewModel { } } + // 회고 삭제 func deleteReflection(date: String) { if reflections.removeValue(forKey: date) != nil { print("회고가 삭제되었습니다.\n") @@ -43,6 +62,7 @@ class ReflectionViewModel { } } + // 전체 회고 목록 출력 func printAllReflection() { print("=== 저장된 회고 목록 ===") for reflection in reflections.values { From 27da5e0296bc9262e2cf9816516ee40b13b9f01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AF=BC=EC=A4=80?= <132960058+aado97@users.noreply.github.com> Date: Tue, 11 Feb 2025 22:51:30 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[#13]=20Date=EB=A1=9C=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=ED=96=88=EB=8A=94=EB=8D=B0=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20=EB=82=A0=EC=A7=9C=EA=B0=80=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EC=95=88=EB=90=98=EB=8A=94=20=EC=9D=B4=EC=8A=88=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project.pbxproj" | 12 ++++++ .../Helper/DateHelper.swift" | 40 +++++++++++++++++++ .../Model/Reflection.swift" | 11 ++++- .../View/main.swift" | 10 ++--- .../ViewModel/ReflectionViewModel.swift" | 38 ++++++++++++++---- 5 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 "dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Helper/DateHelper.swift" diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234.xcodeproj/project.pbxproj" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234.xcodeproj/project.pbxproj" index d00500b..1a1ae21 100644 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234.xcodeproj/project.pbxproj" +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234.xcodeproj/project.pbxproj" @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 5907993B2D5B755A00D1D062 /* DateHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5907993A2D5B755A00D1D062 /* DateHelper.swift */; }; 5957EFEA2D59D0700019B873 /* Reflection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5957EFE92D59D0700019B873 /* Reflection.swift */; }; 5957EFEC2D59D1550019B873 /* ReflectionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5957EFEB2D59D1550019B873 /* ReflectionViewModel.swift */; }; 598907C92D461A930024CCEF /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 598907C82D461A930024CCEF /* main.swift */; }; @@ -25,6 +26,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 5907993A2D5B755A00D1D062 /* DateHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateHelper.swift; sourceTree = ""; }; 5957EFE92D59D0700019B873 /* Reflection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reflection.swift; sourceTree = ""; }; 5957EFEB2D59D1550019B873 /* ReflectionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReflectionViewModel.swift; sourceTree = ""; }; 598907C52D461A930024CCEF /* Weekly01_회고시스템 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Weekly01_회고시스템"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -42,6 +44,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 590799372D5B751000D1D062 /* Helper */ = { + isa = PBXGroup; + children = ( + 5907993A2D5B755A00D1D062 /* DateHelper.swift */, + ); + path = Helper; + sourceTree = ""; + }; 5957EFE62D59CAAD0019B873 /* ViewModel */ = { isa = PBXGroup; children = ( @@ -85,6 +95,7 @@ 598907C72D461A930024CCEF /* Weekly01_회고시스템 */ = { isa = PBXGroup; children = ( + 590799372D5B751000D1D062 /* Helper */, 5957EFE82D59CABF0019B873 /* Model */, 5957EFE72D59CAB90019B873 /* View */, 5957EFE62D59CAAD0019B873 /* ViewModel */, @@ -151,6 +162,7 @@ buildActionMask = 2147483647; files = ( 5957EFEA2D59D0700019B873 /* Reflection.swift in Sources */, + 5907993B2D5B755A00D1D062 /* DateHelper.swift in Sources */, 5957EFEC2D59D1550019B873 /* ReflectionViewModel.swift in Sources */, 598907C92D461A930024CCEF /* main.swift in Sources */, ); diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Helper/DateHelper.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Helper/DateHelper.swift" new file mode 100644 index 0000000..a78647c --- /dev/null +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Helper/DateHelper.swift" @@ -0,0 +1,40 @@ +// +// DateHelper.swift +// Weekly01_회고시스템 +// +// Created by 도민준 on 2/11/25. +// + +import Foundation + +class DateHelper { + // 싱글톤 + static let shared = DateHelper() + + private let dateFormats = [ + "yyyy-MM-dd", // 2025-04-12 + "yyMMdd", // 250412 + "yyyy년 M월 d일" // 2025년 4월 12일 + ] + + private var formatters: [DateFormatter] = [] + + private init() { + formatters = dateFormats.map { format in + let formatter = DateFormatter() + formatter.dateFormat = format + formatter.locale = Locale(identifier: "ko_KR") + formatter.timeZone = TimeZone(identifier: "Asia/Seoul") + return formatter + } + } + + func stringToDate(from input: String) -> Date? { + for formatter in formatters { + if let date = formatter.date(from: input) { + return date + } + } + return nil + } +} diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" index 7fdf702..f1ab250 100644 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" @@ -8,6 +8,15 @@ import Foundation struct Reflection { - let date: String + let date: Date var content: String + + // 날짜를 문자열 형태로 변환 (시간 정보 제거) + var dateString: String { + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "ko_KR") + formatter.dateFormat = "yyyy-MM-dd" + formatter.timeStyle = .none + return formatter.string(from: date) + } } diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" index b9b4bb7..c0571c8 100644 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/View/main.swift" @@ -28,22 +28,20 @@ while true { case 1: print("날짜를 입력하세요 (예: 2024-12-25):", terminator: " ") date = readLine() ?? "" - print("회고 내용을 입력하세요:", terminator: " ") - content = readLine() ?? "" - reflectionManager.addReflection(date: date, content: content) + reflectionManager.addReflection(dateString: date) case 2: print("조회할 날짜를 입력하세요:", terminator: " ") date = readLine() ?? "" - reflectionManager.retrieveReflection(date: date) + reflectionManager.retrieveReflection(dateString: date) case 3: print("수정할 날짜를 입력하세요:", terminator: " ") date = readLine() ?? "" - reflectionManager.updateReflection(date: date) + reflectionManager.updateReflection(dateString: date) case 4: print("삭제할 날짜를 입력하세요:", terminator: " ") date = readLine() ?? "" - reflectionManager.deleteReflection(date: date) + reflectionManager.deleteReflection(dateString: date) case 5: reflectionManager.printAllReflection() diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" index fb9164a..307ddba 100644 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" @@ -10,7 +10,7 @@ import Foundation class ReflectionViewModel { //날짜를 키 값으로 정하기 위해 //private 메서드를 통해서만 접근 가능하게 하여 데이터 무결성 유지 - private var reflections: [String: Reflection] = [:] + private var reflections: [Date: Reflection] = [:] // 메뉴 출력 func printMenu() { @@ -26,15 +26,27 @@ class ReflectionViewModel { } // 회고 추가 - func addReflection(date: String, content: String) { + func addReflection(dateString: String) { + guard let date = DateHelper.shared.stringToDate(from: dateString) else { + print("잘못된 날짜 형식입니다.\n") + return + } + print("회고 내용을 입력하세요:", terminator: " ") + let content = readLine() ?? "" + reflections[date] = Reflection(date: date, content: content) print("회고가 추가 되었습니다.\n") } // 회고 조회 - func retrieveReflection(date: String) { + func retrieveReflection(dateString: String) { + guard let date = DateHelper.shared.stringToDate(from: dateString) else { + print("잘못된 날짜 형식입니다.\n") + return + } + if let reflection = reflections[date] { - print("날짜: \(reflection.date)") + print("날짜: \(reflection.dateString)") print("내용: \(reflection.content)\n") } else { print("해당 날짜의 회고가 없습니다.\n") @@ -42,10 +54,15 @@ class ReflectionViewModel { } // 회고 수정 - func updateReflection(date: String) { + func updateReflection(dateString: String) { + guard let date = DateHelper.shared.stringToDate(from: dateString) else { + print("잘못된 날짜 형식입니다.\n") + return + } + if reflections[date] != nil { print("새로운 회고 내용을 입력하세요: ", terminator: " ") - var newContent = readLine() ?? "" + let newContent = readLine() ?? "" reflections[date]?.content = newContent print("회고가 수정되었습니다.\n") } else { @@ -54,7 +71,12 @@ class ReflectionViewModel { } // 회고 삭제 - func deleteReflection(date: String) { + func deleteReflection(dateString: String) { + guard let date = DateHelper.shared.stringToDate(from: dateString) else { + print("잘못된 날짜 형식입니다.\n") + return + } + if reflections.removeValue(forKey: date) != nil { print("회고가 삭제되었습니다.\n") } else { @@ -66,7 +88,7 @@ class ReflectionViewModel { func printAllReflection() { print("=== 저장된 회고 목록 ===") for reflection in reflections.values { - print("날짜: \(reflection.date)") + print("날짜: \(reflection.dateString)") print("내용: \(reflection.content)") } } From 06f7acd9a9dcc95095fc7cb875d6446ade38d2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AF=BC=EC=A4=80?= <132960058+aado97@users.noreply.github.com> Date: Tue, 11 Feb 2025 23:08:50 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[#13]=20Date=20=EC=9D=B4=EC=8A=88=EB=8A=94?= =?UTF-8?q?=20=EB=82=B4=EC=9D=BC=20=EC=8A=A4=ED=84=B0=EB=94=94=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=9E=A1=EA=B2=A0=EC=8A=B5=EB=8B=88=EB=8B=A4,,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helper/DateHelper.swift" | 6 +++++- .../Model/Reflection.swift" | 1 + .../ViewModel/ReflectionViewModel.swift" | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Helper/DateHelper.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Helper/DateHelper.swift" index a78647c..ef9cecd 100644 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Helper/DateHelper.swift" +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Helper/DateHelper.swift" @@ -32,7 +32,11 @@ class DateHelper { func stringToDate(from input: String) -> Date? { for formatter in formatters { if let date = formatter.date(from: input) { - return date + // 자정으로 설정하여 시간 정보 제거 + let calendar = Calendar.current + let normalizedDate = calendar.startOfDay(for: date) // 시간 제거 + print("변환된 날짜: \(normalizedDate)") // 디버깅용 출력 + return calendar.startOfDay(for: date) } } return nil diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" index f1ab250..a617b22 100644 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Model/Reflection.swift" @@ -16,6 +16,7 @@ struct Reflection { let formatter = DateFormatter() formatter.locale = Locale(identifier: "ko_KR") formatter.dateFormat = "yyyy-MM-dd" + formatter.timeZone = TimeZone(identifier: "Asia/Seoul") // 한국 시간으로 변환 formatter.timeStyle = .none return formatter.string(from: date) } diff --git "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" index 307ddba..ba32f1f 100644 --- "a/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" +++ "b/dominjun/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/Weekly01_\355\232\214\352\263\240\354\213\234\354\212\244\355\205\234/ViewModel/ReflectionViewModel.swift" @@ -31,6 +31,10 @@ class ReflectionViewModel { print("잘못된 날짜 형식입니다.\n") return } + + let normalizedDate = Calendar.current.startOfDay(for: date) // 시간 제거 + print("조회 변환된 날짜: \(normalizedDate)") // 디버깅용 출력 + print("회고 내용을 입력하세요:", terminator: " ") let content = readLine() ?? ""