diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..3186131 Binary files /dev/null and b/.DS_Store differ diff --git a/MyCreditManager_2_rlatnrud9820.xcodeproj/project.pbxproj b/MyCreditManager_2_rlatnrud9820.xcodeproj/project.pbxproj new file mode 100644 index 0000000..658f2ef --- /dev/null +++ b/MyCreditManager_2_rlatnrud9820.xcodeproj/project.pbxproj @@ -0,0 +1,312 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 55; + objects = { + +/* Begin PBXBuildFile section */ + 530644812A8E25B500EC05DD /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 530644802A8E25B500EC05DD /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 5306447B2A8E25B500EC05DD /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 12; + dstPath = MyCreditManager_2_rlatnrud9820/raw/student.txt; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 5328C0402A8F69E900EE5CF6 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 5306447D2A8E25B500EC05DD /* MyCreditManager_2_rlatnrud9820 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MyCreditManager_2_rlatnrud9820; sourceTree = BUILT_PRODUCTS_DIR; }; + 530644802A8E25B500EC05DD /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = main.swift; path = MyCreditManager_2_rlatnrud9820/main.swift; sourceTree = SOURCE_ROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 5306447A2A8E25B500EC05DD /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 530644742A8E25B500EC05DD = { + isa = PBXGroup; + children = ( + 5306447F2A8E25B500EC05DD /* MyCreditManager_2_rlatnrud9820 */, + 5306447E2A8E25B500EC05DD /* Products */, + ); + sourceTree = ""; + }; + 5306447E2A8E25B500EC05DD /* Products */ = { + isa = PBXGroup; + children = ( + 5306447D2A8E25B500EC05DD /* MyCreditManager_2_rlatnrud9820 */, + ); + name = Products; + sourceTree = ""; + }; + 5306447F2A8E25B500EC05DD /* MyCreditManager_2_rlatnrud9820 */ = { + isa = PBXGroup; + children = ( + 530644802A8E25B500EC05DD /* main.swift */, + ); + path = MyCreditManager_2_rlatnrud9820; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 5306447C2A8E25B500EC05DD /* MyCreditManager_2_rlatnrud9820 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 530644842A8E25B500EC05DD /* Build configuration list for PBXNativeTarget "MyCreditManager_2_rlatnrud9820" */; + buildPhases = ( + 530644792A8E25B500EC05DD /* Sources */, + 5306447A2A8E25B500EC05DD /* Frameworks */, + 5306447B2A8E25B500EC05DD /* CopyFiles */, + 532C504A2A8E8CE8004B1599 /* Resources */, + 5328C0402A8F69E900EE5CF6 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MyCreditManager_2_rlatnrud9820; + productName = MyCreditManager_2_KSK9820; + productReference = 5306447D2A8E25B500EC05DD /* MyCreditManager_2_rlatnrud9820 */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 530644752A8E25B500EC05DD /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1320; + LastUpgradeCheck = 1320; + TargetAttributes = { + 5306447C2A8E25B500EC05DD = { + CreatedOnToolsVersion = 13.2.1; + }; + }; + }; + buildConfigurationList = 530644782A8E25B500EC05DD /* Build configuration list for PBXProject "MyCreditManager_2_rlatnrud9820" */; + compatibilityVersion = "Xcode 13.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 530644742A8E25B500EC05DD; + productRefGroup = 5306447E2A8E25B500EC05DD /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 5306447C2A8E25B500EC05DD /* MyCreditManager_2_rlatnrud9820 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 532C504A2A8E8CE8004B1599 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 530644792A8E25B500EC05DD /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 530644812A8E25B500EC05DD /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 530644822A8E25B500EC05DD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 12.1; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 530644832A8E25B500EC05DD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 12.1; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 530644852A8E25B500EC05DD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = CX8P4D8Z7M; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 530644862A8E25B500EC05DD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = CX8P4D8Z7M; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 530644782A8E25B500EC05DD /* Build configuration list for PBXProject "MyCreditManager_2_rlatnrud9820" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 530644822A8E25B500EC05DD /* Debug */, + 530644832A8E25B500EC05DD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 530644842A8E25B500EC05DD /* Build configuration list for PBXNativeTarget "MyCreditManager_2_rlatnrud9820" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 530644852A8E25B500EC05DD /* Debug */, + 530644862A8E25B500EC05DD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 530644752A8E25B500EC05DD /* Project object */; +} diff --git a/MyCreditManager_2_rlatnrud9820.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/MyCreditManager_2_rlatnrud9820.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..43453ee --- /dev/null +++ b/MyCreditManager_2_rlatnrud9820.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/MyCreditManager_2_rlatnrud9820.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/MyCreditManager_2_rlatnrud9820.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/MyCreditManager_2_rlatnrud9820.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/MyCreditManager_2_rlatnrud9820.xcodeproj/project.xcworkspace/xcuserdata/sk.xcuserdatad/UserInterfaceState.xcuserstate b/MyCreditManager_2_rlatnrud9820.xcodeproj/project.xcworkspace/xcuserdata/sk.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..384c0d0 Binary files /dev/null and b/MyCreditManager_2_rlatnrud9820.xcodeproj/project.xcworkspace/xcuserdata/sk.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MyCreditManager_2_rlatnrud9820.xcodeproj/xcuserdata/sk.xcuserdatad/xcschemes/xcschememanagement.plist b/MyCreditManager_2_rlatnrud9820.xcodeproj/xcuserdata/sk.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..c893974 --- /dev/null +++ b/MyCreditManager_2_rlatnrud9820.xcodeproj/xcuserdata/sk.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + MyCreditManager_2_rlatnrud9820.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/MyCreditManager_2_rlatnrud9820/.DS_Store b/MyCreditManager_2_rlatnrud9820/.DS_Store new file mode 100644 index 0000000..6966cbb Binary files /dev/null and b/MyCreditManager_2_rlatnrud9820/.DS_Store differ diff --git a/MyCreditManager_2_rlatnrud9820/main.swift b/MyCreditManager_2_rlatnrud9820/main.swift new file mode 100644 index 0000000..52de485 --- /dev/null +++ b/MyCreditManager_2_rlatnrud9820/main.swift @@ -0,0 +1,262 @@ +// +// main.swift +// MyCreditManager_2_rlatnrud9820 +// +// Created by 김수경 on 2023/08/16. +// + +import Foundation + + +enum WrongInput: Error, CustomDebugStringConvertible { + + case menuWrongInput + case commonWrongInput + case duplicatedInput(name: String) + case nonExistentInput(name: String) + case nonExistentSubject(name: String, subject: String) + + var debugDescription: String { + switch self { + case .menuWrongInput: + return "뭔가 입력이 잘못되었습니다. 1~5 사이의 숫자 혹은 X를 입력해주세요." + case .commonWrongInput: + return "입력이 잘못되었습니다. 다시 확인해주세요." + case .duplicatedInput(let name): + return "\(name)은 이미 존재하는 학생입니다. 추가하지 않습니다." + case .nonExistentInput(let name): + return "\(name) 학생을 찾지 못했습니다." + case .nonExistentSubject(let name, let subject): + return "\(name) 학생의 \(subject) 성적을 찾지 못했습니다." + default: + return "입력이 잘못되었습니다. 다시 확인해주세요." + } + } + +} + + +struct Subject : Codable{ + let subject: String + var grade: String +} + +struct Student : Codable{ + var data: [String: [Subject]] +} + + +class MyCreditManager{ + var isRunning = true + var student: [String: [Subject]] = [:] + + + func run(){ + + let stu: Student = loadJsonFile() ?? Student(data: [:]) + student = stu.data + + + while (isRunning){ + switch self.menu() { + case "1": + do { try addStudent() } catch { + print(error) + } + case "2": + do { try deleteStudent() } catch { + print(error) + } + case "3": + do { try changeGrade() } catch { + print(error) + } + case "4": + do { try deleteGrade() } catch { + print(error) + } + case "5": + do { try viewGrade() } catch { + print(error) + } + case "X": + exitProgram() + default: + do { try ErrorMessage() } catch{ + print(error) + } + } + } + } + + + private func menu() -> String { + print("원하는 기능을 입력해주세요.\n1: 학생추가, 2: 학생삭제, 3: 성적추가(변경), 4: 성적삭제, 5: 평점보기, X: 종료") + return readLine() ?? "0" + } + + private func addStudent() throws { + print("추가할 학생의 이름을 입력해주세요") + + guard let name = readLine(), + !name.isEmpty, name.trimmingCharacters(in: [" "]).count != 0 else { + throw WrongInput.commonWrongInput + } + if let _ = student[name]{ + throw WrongInput.duplicatedInput(name: name) + } + + student[name] = [Subject]() + print("\(name) 학생을 추가했습니다.") + } + + private func deleteStudent() throws { + print("삭제할 학생의 이름을 입력해주세요") + + guard let name = readLine(), + !name.isEmpty, name.trimmingCharacters(in: [" "]).count != 0 else { + throw WrongInput.commonWrongInput + } + + if student[name] == nil { + throw WrongInput.nonExistentInput(name: name) + } + + student[name] = nil + print("\(name) 학생을 삭제하였습니다.") + } + + private func changeGrade() throws { + print("성적을 추가할 학생의 이름, 과목 이름, 성적(A+, A, F 등)을 띄어쓰기로 구분하여 차례로 작성해주세요.\n입력예) Mickey Swift A+\n만약에 학생의 성적 중 해당 과목이 존재한다면 기존 점수가 갱신됩니다.") + + guard let input = readLine(), + !input.isEmpty, input.trimmingCharacters(in: [" "]).count != 0, input.split(separator: " ").count == 3 else { + throw WrongInput.commonWrongInput + } + + let inputArr = input.split(separator: " ").map { String($0) } + let (name, subject, grade) = (inputArr[0], inputArr[1], inputArr[2]) + if student[name] == nil { + throw WrongInput.nonExistentInput(name: name) + } + + if let hadSubject = student[name]?.firstIndex(where: { $0.subject == subject }) { + student[name]?.remove(at: hadSubject) + student[name]?.append(Subject(subject: subject, grade: grade)) + }else{ + student[name]?.append(Subject(subject: subject, grade: grade)) + } + + print("\(name) 학생의 \(subject) 과목이 \(grade)로 추가(변경)되었습니다.") + } + + private func deleteGrade() throws{ + print("성적을 삭제할 학생의 이름, 과목 이름을 띄어쓰기로 구분하여 차례로 작성해주세요.\n입력예) Mickey Swift") + + guard let input = readLine(), + !input.isEmpty, input.trimmingCharacters(in: [" "]).count != 0, input.split(separator: " ").count == 2 else { + throw WrongInput.commonWrongInput + } + let inputArr = input.split(separator: " ").map { String($0) } + let (name, subject) = (inputArr[0], inputArr[1]) + + if student[name] == nil { + throw WrongInput.nonExistentInput(name: name) + }else{ + if let hadSubject = student[name]?.firstIndex(where: { $0.subject == subject }) { + student[name]?.remove(at: hadSubject) + print("\(name) 학생의 \(subject) 과목의 성적이 삭제되었습니다.") + }else{ + throw WrongInput.nonExistentSubject(name: name, subject: subject) + } + } + } + + private func viewGrade() throws { + print("평점을 알고싶은 학생의 이름을 입력해주세요") + + guard let name = readLine(), + !name.isEmpty, name.trimmingCharacters(in: [" "]).count != 0 else { + throw WrongInput.commonWrongInput + } + if student[name] == nil { + throw WrongInput.nonExistentInput(name: name) + } + + for subj in student[name]! { + print("\(subj.subject): \(subj.grade)") + } + + print("평점: \(String(format: "%.2f", gradeCalculator(grade: student[name]!)) )") + } + + private func exitProgram(){ + isRunning = false + saveJsonData(data: Student(data: student)) + print("프로그램을 종료합니다...") + } + + private func ErrorMessage() throws{ + throw WrongInput.menuWrongInput + } + + func gradeCalculator(grade: [Subject]) -> Double { + let score = ["A+": 4.5, "A": 4.0, "B+": 3.5, "B": 3.0, "C+": 2.5, "C": 2.0, "D+": 1.5, "D": 1.0] + return grade.map{ score[$0.grade] ?? 0.0 }.reduce(0.0, +) / Double(grade.count) + } + + + + + func saveJsonData(data:Student) { + let jsonEncoder = JSONEncoder() + + do { + let encodedData = try jsonEncoder.encode(data) + + guard let documentDirectoryUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return } + let fileURL = documentDirectoryUrl.appendingPathComponent("SeSAC_rlatnrud9820.json") + + do { + try encodedData.write(to: fileURL) + } + catch let error as NSError { + print(error) + } + + } catch { + print(error) + } + + } + + + func loadJsonFile() -> Student?{ + let jsongDecoder = JSONDecoder() + + do { + guard let documentDirectoryUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return nil} + + let fileURL = documentDirectoryUrl.appendingPathComponent("SeSAC_rlatnrud9820.json") + + do { + if !FileManager.default.fileExists(atPath: fileURL.path) { + try FileManager.default.createFile(atPath: fileURL.pathExtension, contents: nil) + return nil + } + } catch { + print("create folder error. do something") + } + + let jsonData = try Data(contentsOf: fileURL, options: .mappedIfSafe) + let decodedStudent = try jsongDecoder.decode(Student.self, from: jsonData) + return decodedStudent + } + catch { + print(error) + return nil + } + } +} + +MyCreditManager().run()