diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..aeab5ff Binary files /dev/null and b/.DS_Store differ diff --git a/Model/CoreDataManager.swift b/Model/CoreDataManager.swift new file mode 100644 index 0000000..ecf39a7 --- /dev/null +++ b/Model/CoreDataManager.swift @@ -0,0 +1,74 @@ +// +// CoreDataManager.swift +// MyCreditManager_dosh.kor +// +// Created by 신동오 on 2022/12/06. +// + +import Foundation +import CoreData + +final class CoreDataManager { + + // singleton + static let shared: CoreDataManager = CoreDataManager() + + let modelName: String = "GradeCard" + + // Persistent Container load + lazy var persistentContainer: NSPersistentContainer = { + let container = NSPersistentContainer(name: "Model") + container.loadPersistentStores(completionHandler: { (storeDescription, error) in + if let error = error as NSError? { + fatalError("Unresolved error \(error), \(error.userInfo)") + } + }) + return container + }() + + // Managed Object Context + var context: NSManagedObjectContext { + return persistentContainer.viewContext + } + + func saveToContext() { + if context.hasChanges { + do { + try context.save() + } catch { + print(error.localizedDescription) + } + } + } + + func readGradeCards() -> [GradeCard] { + var gradeCardArray:[GradeCard] = [] + let request = NSFetchRequest(entityName: modelName) + + do { + if let fetchedGradeCard = try context.fetch(request) as? [GradeCard] { + gradeCardArray = fetchedGradeCard + } + } catch { + print("read() 실패", error.localizedDescription) + } + + return gradeCardArray + } + + func createGradeCard(name: String, subject: String?, grade: String?) { + if let entity = NSEntityDescription.entity(forEntityName: modelName, in: context){ + if let gradeCard = NSManagedObject(entity: entity, insertInto: context) as? GradeCard { + gradeCard.name = name + gradeCard.subject = subject ?? "empty" + gradeCard.grade = grade ?? "empty" + self.saveToContext() + } + } + } + + func deleteGradeCard(data: GradeCard) { + context.delete(data) + self.saveToContext() + } +} diff --git a/Model/GradeCard+CoreDataClass.swift b/Model/GradeCard+CoreDataClass.swift new file mode 100644 index 0000000..76e83ad --- /dev/null +++ b/Model/GradeCard+CoreDataClass.swift @@ -0,0 +1,15 @@ +// +// GradeCard+CoreDataClass.swift +// MyCreditManager_dosh.kor +// +// Created by 신동오 on 2022/12/06. +// +// + +import Foundation +import CoreData + +@objc(GradeCard) +public class GradeCard: NSManagedObject { + +} diff --git a/Model/GradeCard+CoreDataProperties.swift b/Model/GradeCard+CoreDataProperties.swift new file mode 100644 index 0000000..7e92a52 --- /dev/null +++ b/Model/GradeCard+CoreDataProperties.swift @@ -0,0 +1,27 @@ +// +// GradeCard+CoreDataProperties.swift +// MyCreditManager_dosh.kor +// +// Created by 신동오 on 2022/12/06. +// +// + +import Foundation +import CoreData + + +extension GradeCard { + + @nonobjc public class func fetchRequest() -> NSFetchRequest { + return NSFetchRequest(entityName: "GradeCard") + } + + @NSManaged public var grade: String? + @NSManaged public var name: String? + @NSManaged public var subject: String? + +} + +extension GradeCard : Identifiable { + +} diff --git a/Model/LocalItem.swift b/Model/LocalItem.swift new file mode 100644 index 0000000..07027ca --- /dev/null +++ b/Model/LocalItem.swift @@ -0,0 +1,10 @@ +// +// LocalItem.swift +// MyCreditManager_dosh.kor +// +// Created by 신동오 on 2022/12/08. +// + +import Foundation + +let permittedString: [String] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", " "] diff --git a/MyCreditManager_dosh.kor.xcodeproj/project.pbxproj b/MyCreditManager_dosh.kor.xcodeproj/project.pbxproj new file mode 100644 index 0000000..64cef95 --- /dev/null +++ b/MyCreditManager_dosh.kor.xcodeproj/project.pbxproj @@ -0,0 +1,326 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + E7C6572F293F62960072B439 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7C6572E293F62960072B439 /* main.swift */; }; + E7C6574A293F674E0072B439 /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = E7C65748293F674E0072B439 /* Model.xcdatamodeld */; }; + E7C65751293F67E70072B439 /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7C65750293F67E70072B439 /* CoreDataManager.swift */; }; + E7C65754293F691C0072B439 /* GradeCard+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7C65752293F691C0072B439 /* GradeCard+CoreDataClass.swift */; }; + E7C65755293F691C0072B439 /* GradeCard+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7C65753293F691C0072B439 /* GradeCard+CoreDataProperties.swift */; }; + E7F3CC71294171C400DDC821 /* LocalItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7F3CC70294171C300DDC821 /* LocalItem.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + E7C65729293F62960072B439 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + E7C6572B293F62960072B439 /* MyCreditManager_dosh.kor */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MyCreditManager_dosh.kor; sourceTree = BUILT_PRODUCTS_DIR; }; + E7C6572E293F62960072B439 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + E7C65749293F674E0072B439 /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = ""; }; + E7C65750293F67E70072B439 /* CoreDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = ""; }; + E7C65752293F691C0072B439 /* GradeCard+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GradeCard+CoreDataClass.swift"; sourceTree = ""; }; + E7C65753293F691C0072B439 /* GradeCard+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GradeCard+CoreDataProperties.swift"; sourceTree = ""; }; + E7F3CC70294171C300DDC821 /* LocalItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalItem.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + E7C65728293F62960072B439 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + E7C65722293F62960072B439 = { + isa = PBXGroup; + children = ( + E7C6574F293F67A70072B439 /* Model */, + E7C6572D293F62960072B439 /* MyCreditManager_dosh.kor */, + E7C6572C293F62960072B439 /* Products */, + ); + sourceTree = ""; + }; + E7C6572C293F62960072B439 /* Products */ = { + isa = PBXGroup; + children = ( + E7C6572B293F62960072B439 /* MyCreditManager_dosh.kor */, + ); + name = Products; + sourceTree = ""; + }; + E7C6572D293F62960072B439 /* MyCreditManager_dosh.kor */ = { + isa = PBXGroup; + children = ( + E7C6572E293F62960072B439 /* main.swift */, + E7C65748293F674E0072B439 /* Model.xcdatamodeld */, + ); + path = MyCreditManager_dosh.kor; + sourceTree = ""; + }; + E7C6574F293F67A70072B439 /* Model */ = { + isa = PBXGroup; + children = ( + E7C65752293F691C0072B439 /* GradeCard+CoreDataClass.swift */, + E7C65753293F691C0072B439 /* GradeCard+CoreDataProperties.swift */, + E7C65750293F67E70072B439 /* CoreDataManager.swift */, + E7F3CC70294171C300DDC821 /* LocalItem.swift */, + ); + path = Model; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + E7C6572A293F62960072B439 /* MyCreditManager_dosh.kor */ = { + isa = PBXNativeTarget; + buildConfigurationList = E7C65732293F62960072B439 /* Build configuration list for PBXNativeTarget "MyCreditManager_dosh.kor" */; + buildPhases = ( + E7C65727293F62960072B439 /* Sources */, + E7C65728293F62960072B439 /* Frameworks */, + E7C65729293F62960072B439 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MyCreditManager_dosh.kor; + productName = MyCreditManager_dosh.kor; + productReference = E7C6572B293F62960072B439 /* MyCreditManager_dosh.kor */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + E7C65723293F62960072B439 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1410; + LastUpgradeCheck = 1410; + TargetAttributes = { + E7C6572A293F62960072B439 = { + CreatedOnToolsVersion = 14.1; + }; + }; + }; + buildConfigurationList = E7C65726293F62960072B439 /* Build configuration list for PBXProject "MyCreditManager_dosh.kor" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = E7C65722293F62960072B439; + productRefGroup = E7C6572C293F62960072B439 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + E7C6572A293F62960072B439 /* MyCreditManager_dosh.kor */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + E7C65727293F62960072B439 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E7F3CC71294171C400DDC821 /* LocalItem.swift in Sources */, + E7C6572F293F62960072B439 /* main.swift in Sources */, + E7C65754293F691C0072B439 /* GradeCard+CoreDataClass.swift in Sources */, + E7C65751293F67E70072B439 /* CoreDataManager.swift in Sources */, + E7C65755293F691C0072B439 /* GradeCard+CoreDataProperties.swift in Sources */, + E7C6574A293F674E0072B439 /* Model.xcdatamodeld in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + E7C65730293F62960072B439 /* 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++20"; + 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.6; + 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; + }; + E7C65731293F62960072B439 /* 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++20"; + 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.6; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + E7C65733293F62960072B439 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + E7C65734293F62960072B439 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + E7C65726293F62960072B439 /* Build configuration list for PBXProject "MyCreditManager_dosh.kor" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E7C65730293F62960072B439 /* Debug */, + E7C65731293F62960072B439 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + E7C65732293F62960072B439 /* Build configuration list for PBXNativeTarget "MyCreditManager_dosh.kor" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E7C65733293F62960072B439 /* Debug */, + E7C65734293F62960072B439 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCVersionGroup section */ + E7C65748293F674E0072B439 /* Model.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + E7C65749293F674E0072B439 /* Model.xcdatamodel */, + ); + currentVersion = E7C65749293F674E0072B439 /* Model.xcdatamodel */; + path = Model.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ + }; + rootObject = E7C65723293F62960072B439 /* Project object */; +} diff --git a/MyCreditManager_dosh.kor.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/MyCreditManager_dosh.kor.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/MyCreditManager_dosh.kor.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/MyCreditManager_dosh.kor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/MyCreditManager_dosh.kor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/MyCreditManager_dosh.kor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/MyCreditManager_dosh.kor.xcodeproj/project.xcworkspace/xcuserdata/dosh.kor.xcuserdatad/UserInterfaceState.xcuserstate b/MyCreditManager_dosh.kor.xcodeproj/project.xcworkspace/xcuserdata/dosh.kor.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..02d5715 Binary files /dev/null and b/MyCreditManager_dosh.kor.xcodeproj/project.xcworkspace/xcuserdata/dosh.kor.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MyCreditManager_dosh.kor.xcodeproj/xcuserdata/dosh.kor.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/MyCreditManager_dosh.kor.xcodeproj/xcuserdata/dosh.kor.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..6593849 --- /dev/null +++ b/MyCreditManager_dosh.kor.xcodeproj/xcuserdata/dosh.kor.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,24 @@ + + + + + + + + + diff --git a/MyCreditManager_dosh.kor.xcodeproj/xcuserdata/dosh.kor.xcuserdatad/xcschemes/xcschememanagement.plist b/MyCreditManager_dosh.kor.xcodeproj/xcuserdata/dosh.kor.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..17698cb --- /dev/null +++ b/MyCreditManager_dosh.kor.xcodeproj/xcuserdata/dosh.kor.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + MyCreditManager_dosh.kor.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/MyCreditManager_dosh.kor/Model.xcdatamodeld/Model.xcdatamodel/contents b/MyCreditManager_dosh.kor/Model.xcdatamodeld/Model.xcdatamodel/contents new file mode 100644 index 0000000..219e3b2 --- /dev/null +++ b/MyCreditManager_dosh.kor/Model.xcdatamodeld/Model.xcdatamodel/contents @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/MyCreditManager_dosh.kor/main.swift b/MyCreditManager_dosh.kor/main.swift new file mode 100644 index 0000000..a3297c0 --- /dev/null +++ b/MyCreditManager_dosh.kor/main.swift @@ -0,0 +1,381 @@ +// +// main.swift +// MyCreditManager_dosh.kor +// +// Created by 신동오 on 2022/12/06. +// + +import Foundation +import CoreData + +let dataManager = CoreDataManager() + +while true { + + var finishFlag = 0 + + print("원하는 기능을 입력해주세요 \n 1: 학생추가, 2: 학생삭제, 3: 성적추가(변경), 4: 성적삭제, 5: 평점보기, X: 종료") + let menuInput = readLine() + + if menuInput == "X" { + print("프로그램을 종료합니다...") + break + } + + switch menuInput { + case "1": + print("추가할 학생의 이름을 입력해주세요") + + let userInput = readLine() + + // ==================== input check(S) ==================== + // 곧바로 엔터친 경우 + if userInput == "" { + print("입력이 잘못되었습니다. 다시 확인해 주세요") + break + } + + // 스페이스가 포함된 경우 + if let userInput = userInput { + if userInput.contains(" ") { + print("입력이 잘못되었습니다. 다시 확인해 주세요") + break + } + } + + // 알파벳, 숫자, + 기호 이외 문자를 입력한 경우 + for i in userInput! { + if permittedString.contains(String(i)) == false { + print("알파벳 대문자, 소문자, 숫자, + 기호만 입력이 가능합니다.") + finishFlag = 1 + break + } + } + + if finishFlag == 1 { break } + // ==================== input check(E) ==================== + // 이미 등록된 이름인지 확인 + let gradeCardArray: [GradeCard] = dataManager.readGradeCards() + for gradeCard in gradeCardArray { + if let name = gradeCard.name { + if name == userInput! { + print("\(name)은 이미 존재하는 학생입니다. 추가하지 않습니다.") + finishFlag = 1 + break + } + } + } + + if finishFlag == 1 { break } + + // 입력받은 이름을 저장한다. + dataManager.createGradeCard(name: userInput!, subject: nil, grade: nil) + print("\(userInput!) 학생을 추가했습니다.") + + case "2": + print("삭제할 학생의 이름을 입력해주세요") + + let userInput = readLine() + + // ==================== input check(S) ==================== + // 곧바로 엔터친 경우 + if userInput == "" { + print("입력이 잘못되었습니다. 다시 확인해 주세요") + break + } + + // 스페이스가 포함된 경우 + if let userInput = userInput { + if userInput.contains(" ") { + print("입력이 잘못되었습니다. 다시 확인해 주세요") + break + } + } + // 알파벳, 숫자, + 기호 이외 문자를 입력한 경우 + for i in userInput! { + if permittedString.contains(String(i)) == false { + print("알파벳 대문자, 소문자, 숫자, + 기호만 입력이 가능합니다.") + finishFlag = 1 + break + } + } + + if finishFlag == 1 { break } + // ==================== input check(E) ==================== + + // context 에서 데이터 가져오기 + let fetchedGradeCards: [GradeCard] = dataManager.readGradeCards() + var willBeDeletedGradeCards: [GradeCard] = [] + + for fetchedGradeCard in fetchedGradeCards { + if fetchedGradeCard.name == userInput { + willBeDeletedGradeCards.append(fetchedGradeCard) + } + } + + // 입력 받은 이름이 context 에 있는/없는 경우 + if willBeDeletedGradeCards.isEmpty { + print("\(userInput!) 학생을 찾지 못했습니다.") + break + } else { + for willDeleteGradeCard in willBeDeletedGradeCards { + dataManager.deleteGradeCard(data: willDeleteGradeCard) + } + print("\(userInput!) 학생을 삭제하였습니다.") + } + + case "3": + print("성적을 추가할 학생의 이름, 과목 이름, 성적(A+, A0, F 등)을 띄어쓰기로 구분하여 차례로 작성해 주세요.\n 입력예) Mickey Swift A+ \n 만약에 학생의 성적 중 해당 과목이 존재하면 기존 점수가 갱신됩니다.") + + let userInput = readLine() + + // ==================== input check(S) ==================== + // 곧바로 엔터친 경우 + if userInput == "" { + print("입력이 잘못되었습니다. 다시 확인해 주세요") + break + } + + // 알파벳, 숫자, + 기호, " " 이외 문자를 입력한 경우 + for i in userInput! { + if permittedString.contains(String(i)) == false { + print("알파벳 대문자, 소문자, 숫자, + 기호만 입력이 가능합니다.") + finishFlag = 1 + break + } + } + + if finishFlag == 1 { break } + + // 스페이스를 두 번 입력하였는가?(3개의 단어로 쪼개지는지) + if userInput!.filter({ $0 == " "}).count != 2 { + print("입력이 잘못되었습니다. 다시 확인해 주세요") + break + } + // 스페이스 두 번이 연속으로 친건 아닌가? + let changeSpaceString = userInput!.replacingOccurrences(of: " ", with: "*") + if changeSpaceString.contains("**") { + print("입력이 잘못되었습니다. 다시 확인해 주세요") + break + } + // ==================== input check(E) ==================== + + // 입력을 name, subject, grade 로 분리하기 + let firstSpaceIndex = userInput!.firstIndex(of: " ")! + let lastSpaceIndex = userInput!.lastIndex(of: " ")! + + let behindOfFirstSpaceIndex = userInput!.index(firstSpaceIndex, offsetBy: 1) + let behindOfSecondSpaceIndex = userInput!.index(lastSpaceIndex, offsetBy: 1) + + let name = String(userInput![..