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..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,9 @@ 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 */; }; /* End PBXBuildFile section */ @@ -23,6 +26,9 @@ /* 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; }; 598907C82D461A930024CCEF /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -38,6 +44,38 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 590799372D5B751000D1D062 /* Helper */ = { + isa = PBXGroup; + children = ( + 5907993A2D5B755A00D1D062 /* DateHelper.swift */, + ); + path = Helper; + sourceTree = ""; + }; + 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 +95,10 @@ 598907C72D461A930024CCEF /* Weekly01_회고시스템 */ = { isa = PBXGroup; children = ( - 598907C82D461A930024CCEF /* main.swift */, + 590799372D5B751000D1D062 /* Helper */, + 5957EFE82D59CABF0019B873 /* Model */, + 5957EFE72D59CAB90019B873 /* View */, + 5957EFE62D59CAAD0019B873 /* ViewModel */, ); path = "Weekly01_회고시스템"; sourceTree = ""; @@ -120,6 +161,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5957EFEA2D59D0700019B873 /* Reflection.swift in Sources */, + 5907993B2D5B755A00D1D062 /* DateHelper.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/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..ef9cecd --- /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,44 @@ +// +// 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) { + // 자정으로 설정하여 시간 정보 제거 + 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" new file mode 100644 index 0000000..a617b22 --- /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,23 @@ +// +// Reflection.swift +// Weekly01_회고시스템 +// +// Created by 도민준 on 2/10/25. +// + +import Foundation + +struct Reflection { + let date: Date + var content: String + + // 날짜를 문자열 형태로 변환 (시간 정보 제거) + var dateString: String { + 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/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..c0571c8 --- /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,52 @@ +// +// main.swift +// Weekly01_회고시스템 +// +// Created by 도민준 on 1/26/25. +// + +import Foundation + +var reflectionManager = ReflectionViewModel() +var menuNum = 0 +var date = "" +var content = "" + +reflectionManager.printMenu() + +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() ?? "" + reflectionManager.addReflection(dateString: date) + + case 2: + print("조회할 날짜를 입력하세요:", terminator: " ") + date = readLine() ?? "" + reflectionManager.retrieveReflection(dateString: date) + case 3: + print("수정할 날짜를 입력하세요:", terminator: " ") + date = readLine() ?? "" + reflectionManager.updateReflection(dateString: date) + case 4: + print("삭제할 날짜를 입력하세요:", terminator: " ") + date = readLine() ?? "" + reflectionManager.deleteReflection(dateString: date) + + case 5: + reflectionManager.printAllReflection() + default: + 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" new file mode 100644 index 0000000..ba32f1f --- /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,99 @@ +// +// ReflectionViewModel.swift +// Weekly01_회고시스템 +// +// Created by 도민준 on 2/10/25. +// + +import Foundation + +class ReflectionViewModel { + //날짜를 키 값으로 정하기 위해 + //private 메서드를 통해서만 접근 가능하게 하여 데이터 무결성 유지 + private var reflections: [Date: Reflection] = [:] + + // 메뉴 출력 + func printMenu() { + print(""" + === 회고 시스템 === + 1. 회고 추가 + 2. 회고 조회 + 3. 회고 수정 + 4. 회고 삭제 + 5. 전체 회고 목록 출력 + 6. 종료\n + """) + } + + // 회고 추가 + func addReflection(dateString: String) { + guard let date = DateHelper.shared.stringToDate(from: dateString) else { + print("잘못된 날짜 형식입니다.\n") + return + } + + let normalizedDate = Calendar.current.startOfDay(for: date) // 시간 제거 + print("조회 변환된 날짜: \(normalizedDate)") // 디버깅용 출력 + + print("회고 내용을 입력하세요:", terminator: " ") + let content = readLine() ?? "" + + reflections[date] = Reflection(date: date, content: content) + print("회고가 추가 되었습니다.\n") + } + + // 회고 조회 + func retrieveReflection(dateString: String) { + guard let date = DateHelper.shared.stringToDate(from: dateString) else { + print("잘못된 날짜 형식입니다.\n") + return + } + + if let reflection = reflections[date] { + print("날짜: \(reflection.dateString)") + print("내용: \(reflection.content)\n") + } else { + print("해당 날짜의 회고가 없습니다.\n") + } + } + + // 회고 수정 + func updateReflection(dateString: String) { + guard let date = DateHelper.shared.stringToDate(from: dateString) else { + print("잘못된 날짜 형식입니다.\n") + return + } + + if reflections[date] != nil { + print("새로운 회고 내용을 입력하세요: ", terminator: " ") + let newContent = readLine() ?? "" + reflections[date]?.content = newContent + print("회고가 수정되었습니다.\n") + } else { + print("해당 날짜의 회고가 없습니다.\n") + } + } + + // 회고 삭제 + 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 { + print("해당 날짜의 회고가 없습니다.\n") + } + } + + // 전체 회고 목록 출력 + func printAllReflection() { + print("=== 저장된 회고 목록 ===") + for reflection in reflections.values { + print("날짜: \(reflection.dateString)") + 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() - } -} -