Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -23,6 +26,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
5907993A2D5B755A00D1D062 /* DateHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateHelper.swift; sourceTree = "<group>"; };
5957EFE92D59D0700019B873 /* Reflection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reflection.swift; sourceTree = "<group>"; };
5957EFEB2D59D1550019B873 /* ReflectionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReflectionViewModel.swift; sourceTree = "<group>"; };
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 = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -38,6 +44,38 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
590799372D5B751000D1D062 /* Helper */ = {
isa = PBXGroup;
children = (
5907993A2D5B755A00D1D062 /* DateHelper.swift */,
);
path = Helper;
sourceTree = "<group>";
};
5957EFE62D59CAAD0019B873 /* ViewModel */ = {
isa = PBXGroup;
children = (
5957EFEB2D59D1550019B873 /* ReflectionViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
};
5957EFE72D59CAB90019B873 /* View */ = {
isa = PBXGroup;
children = (
598907C82D461A930024CCEF /* main.swift */,
);
path = View;
sourceTree = "<group>";
};
5957EFE82D59CABF0019B873 /* Model */ = {
isa = PBXGroup;
children = (
5957EFE92D59D0700019B873 /* Reflection.swift */,
);
path = Model;
sourceTree = "<group>";
};
598907BC2D461A930024CCEF = {
isa = PBXGroup;
children = (
Expand All @@ -57,7 +95,10 @@
598907C72D461A930024CCEF /* Weekly01_회고시스템 */ = {
isa = PBXGroup;
children = (
598907C82D461A930024CCEF /* main.swift */,
590799372D5B751000D1D062 /* Helper */,
5957EFE82D59CABF0019B873 /* Model */,
5957EFE72D59CAB90019B873 /* View */,
5957EFE62D59CAAD0019B873 /* ViewModel */,
);
path = "Weekly01_회고시스템";
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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)

Comment on lines +27 to +45
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

입력받는 걸 함수화할 수도 있지 않을까요? print문으로 출력할 메세지만 파라미터로 받는다던가, 출력문을 미리 Enum으로 정의해둔다거나 등의 방법으로요!

case 5:
reflectionManager.printAllReflection()
default:
print("잘못된 입력입니다.\n")
}
}

Original file line number Diff line number Diff line change
@@ -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)")
}
}
}
Loading