diff --git a/contactManager.xcodeproj/project.pbxproj b/contactManager.xcodeproj/project.pbxproj new file mode 100644 index 0000000..1f8e86e --- /dev/null +++ b/contactManager.xcodeproj/project.pbxproj @@ -0,0 +1,299 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + 8733744F295C3295000EAC23 /* CheckErrorFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8733744E295C3295000EAC23 /* CheckErrorFunction.swift */; }; + 87C3EE1D295D5ABF00A76712 /* FindContactFuction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87C3EE1C295D5ABF00A76712 /* FindContactFuction.swift */; }; + D9D3AEFD29597A7B0031A2F2 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9D3AEFC29597A7B0031A2F2 /* main.swift */; }; + D9E15C03295C312C003FB06D /* AddContactFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9E15C02295C312C003FB06D /* AddContactFunction.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + D9D3AEF729597A7B0031A2F2 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 8733744E295C3295000EAC23 /* CheckErrorFunction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckErrorFunction.swift; sourceTree = ""; }; + 87C3EE1C295D5ABF00A76712 /* FindContactFuction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FindContactFuction.swift; sourceTree = ""; }; + D9D3AEF929597A7B0031A2F2 /* contactManager */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = contactManager; sourceTree = BUILT_PRODUCTS_DIR; }; + D9D3AEFC29597A7B0031A2F2 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + D9E15C02295C312C003FB06D /* AddContactFunction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddContactFunction.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + D9D3AEF629597A7B0031A2F2 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + D9D3AEF029597A7B0031A2F2 = { + isa = PBXGroup; + children = ( + D9D3AEFB29597A7B0031A2F2 /* contactManager */, + D9D3AEFA29597A7B0031A2F2 /* Products */, + ); + sourceTree = ""; + }; + D9D3AEFA29597A7B0031A2F2 /* Products */ = { + isa = PBXGroup; + children = ( + D9D3AEF929597A7B0031A2F2 /* contactManager */, + ); + name = Products; + sourceTree = ""; + }; + D9D3AEFB29597A7B0031A2F2 /* contactManager */ = { + isa = PBXGroup; + children = ( + D9D3AEFC29597A7B0031A2F2 /* main.swift */, + D9E15C02295C312C003FB06D /* AddContactFunction.swift */, + 8733744E295C3295000EAC23 /* CheckErrorFunction.swift */, + 87C3EE1C295D5ABF00A76712 /* FindContactFuction.swift */, + ); + path = contactManager; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + D9D3AEF829597A7B0031A2F2 /* contactManager */ = { + isa = PBXNativeTarget; + buildConfigurationList = D9D3AF0029597A7B0031A2F2 /* Build configuration list for PBXNativeTarget "contactManager" */; + buildPhases = ( + D9D3AEF529597A7B0031A2F2 /* Sources */, + D9D3AEF629597A7B0031A2F2 /* Frameworks */, + D9D3AEF729597A7B0031A2F2 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = contactManager; + productName = contactManager; + productReference = D9D3AEF929597A7B0031A2F2 /* contactManager */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + D9D3AEF129597A7B0031A2F2 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1420; + LastUpgradeCheck = 1420; + TargetAttributes = { + D9D3AEF829597A7B0031A2F2 = { + CreatedOnToolsVersion = 14.2; + }; + }; + }; + buildConfigurationList = D9D3AEF429597A7B0031A2F2 /* Build configuration list for PBXProject "contactManager" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = D9D3AEF029597A7B0031A2F2; + productRefGroup = D9D3AEFA29597A7B0031A2F2 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + D9D3AEF829597A7B0031A2F2 /* contactManager */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + D9D3AEF529597A7B0031A2F2 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + D9E15C03295C312C003FB06D /* AddContactFunction.swift in Sources */, + D9D3AEFD29597A7B0031A2F2 /* main.swift in Sources */, + 8733744F295C3295000EAC23 /* CheckErrorFunction.swift in Sources */, + 87C3EE1D295D5ABF00A76712 /* FindContactFuction.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + D9D3AEFE29597A7B0031A2F2 /* 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 = 13.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; + }; + D9D3AEFF29597A7B0031A2F2 /* 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 = 13.1; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + D9D3AF0129597A7B0031A2F2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + MACOSX_DEPLOYMENT_TARGET = 13.0; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + D9D3AF0229597A7B0031A2F2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + MACOSX_DEPLOYMENT_TARGET = 13.0; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + D9D3AEF429597A7B0031A2F2 /* Build configuration list for PBXProject "contactManager" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D9D3AEFE29597A7B0031A2F2 /* Debug */, + D9D3AEFF29597A7B0031A2F2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + D9D3AF0029597A7B0031A2F2 /* Build configuration list for PBXNativeTarget "contactManager" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D9D3AF0129597A7B0031A2F2 /* Debug */, + D9D3AF0229597A7B0031A2F2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = D9D3AEF129597A7B0031A2F2 /* Project object */; +} diff --git a/contactManager.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/contactManager.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/contactManager.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/contactManager.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/contactManager.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/contactManager.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/contactManager.xcodeproj/project.xcworkspace/xcuserdata/longlivedrgn.xcuserdatad/UserInterfaceState.xcuserstate b/contactManager.xcodeproj/project.xcworkspace/xcuserdata/longlivedrgn.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..31a1f37 Binary files /dev/null and b/contactManager.xcodeproj/project.xcworkspace/xcuserdata/longlivedrgn.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/contactManager.xcodeproj/xcuserdata/longlivedrgn.xcuserdatad/xcschemes/xcschememanagement.plist b/contactManager.xcodeproj/xcuserdata/longlivedrgn.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..b43cf80 --- /dev/null +++ b/contactManager.xcodeproj/xcuserdata/longlivedrgn.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + contactManager.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/contactManager/AddContactFunction.swift b/contactManager/AddContactFunction.swift new file mode 100644 index 0000000..8ae5cd9 --- /dev/null +++ b/contactManager/AddContactFunction.swift @@ -0,0 +1,44 @@ +func addContact(){ + var isAddContactError: Bool = false + + while !isAddContactError { + print("") + print("연락처 정보를 입력해주세요: ", terminator: "") + + guard let input = readLine(), input != "" else { + print("아무것도 입력되지 않았습니다. 입력 형식을 확인해주세요.") + continue + } + + guard Validation.validateInputBySlash(input: input) else { + print("입력된 정보가 [이름]/[나이]/[전화번호] 형식인지 확인해주세요") + continue + } + + let seperatedInput = input.components(separatedBy:"/") + + let trimSet = seperatedInput.map { + $0.trimmingCharacters(in: [" "]) + } + + let trimName = trimSet[0] + let trimAge = trimSet[1] + let trimNum = trimSet[2] + + let zeroBlankName = trimName.components(separatedBy: [" "]).joined() + + guard errorCheck(trimName: trimName, trimAge: trimAge, trimNum: trimNum) else { + continue + } + + isAddContactError = true + print("입력한 정보는 \(trimAge)세 \(zeroBlankName)(\(trimNum))입니다.\n") + + let contact = Contact(name: zeroBlankName, age: trimAge, phoneNumber: trimNum) + + contacts.insert(contact) + } + +} + + diff --git a/contactManager/CheckErrorFunction.swift b/contactManager/CheckErrorFunction.swift new file mode 100644 index 0000000..05a7d8f --- /dev/null +++ b/contactManager/CheckErrorFunction.swift @@ -0,0 +1,36 @@ +func checkNameError(name: String) -> Bool{ + guard name.range(of: regex, options: .regularExpression) != nil else { + errorTextOutput(with: .name) + return false + } + return true +} + + +func checkAgeError(age: String) -> Bool{ + guard age.allSatisfy({ $0.isNumber}) else { + errorTextOutput(with: .age) + return false + } + guard let changeToInt = Int(age), changeToInt <= 1000 else { + errorTextOutput(with: .age) + return false + } + return true +} + +func checkPhoneNumError(num: String) -> Bool { + guard Validation.validateInputByHyphenNum(input: num), num.components(separatedBy: ["-"]).joined().count >= 9 else { + errorTextOutput(with: .phoneNumber) + return false + } + return true +} + + +func errorCheck(trimName: String, trimAge: String, trimNum: String) -> Bool { + guard checkNameError(name: trimName), checkAgeError(age: trimAge), checkPhoneNumError(num: trimNum) else { + return false + } + return true +} diff --git a/contactManager/FindContactFuction.swift b/contactManager/FindContactFuction.swift new file mode 100644 index 0000000..d482a65 --- /dev/null +++ b/contactManager/FindContactFuction.swift @@ -0,0 +1,10 @@ +func findContact(inputName : String){ + var filteredContacts = contacts.filter { Contact in Contact.name == inputName } + if filteredContacts.count > 0 { + filteredContacts.forEach { print($0.description) } + } else { + print("연락처에 \(inputName) 이(가) 없습니다.\n") + } +} + + diff --git a/contactManager/main.swift b/contactManager/main.swift new file mode 100644 index 0000000..660a67a --- /dev/null +++ b/contactManager/main.swift @@ -0,0 +1,89 @@ +import Foundation + +struct Contact : Hashable { + let name : String + let age : String + let phoneNumber : String + + var description: String { + "- \(self.name) / \(self.age) / \(self.phoneNumber)" + } +} + +enum ErrorType{ + case name + case age + case phoneNumber +} + +enum GuideText { + static let menu = "1) 연락처 추가 2) 연락처 목록보기 3) 연락처 검색 x) 종료" + static let selectMenu = "메뉴를 선택해주세요 : " +} + +enum MenuType: String { + case addContact = "1" + case viewContactList = "2" + case findContact = "3" + case exit = "x" +} + +struct Validation { + static func validateInputBySlash(input: String) -> Bool { + guard (input.filter{ $0 == "/" }.count == 2) else { + return false + } + return true + } + + static func validateInputByHyphenNum(input: String) -> Bool { + guard (input.filter { $0 == "-" }.count == 2) else { + return false + } + return true + } +} + +func errorTextOutput(with type: ErrorType){ + let errorText: String + switch type { + case .name: errorText = "이름" + case .age: errorText = "나이" + case .phoneNumber: errorText = "연락처" + } + print("입력한 \(errorText)정보가 잘못되었습니다. 입력 형식을 확인해주세요.") +} + +var contacts : Set = [] + +var isMenuInputError: Bool = false +let regex = "^[A-Za-z\\s]+$" + +while !isMenuInputError { + print(GuideText.menu) + print(GuideText.selectMenu,terminator: "") + guard let input = readLine(), let menu = MenuType(rawValue: input) else{ + print("선택이 잘못되었습니다. 확인 후 다시 입력해주세요.\n") + continue + } + switch menu{ + case .addContact: + addContact() + case .viewContactList: + for contact in contacts.sorted(by: {$0.name < $1.name}) { + print(contact.description) + } + print("") + continue + case .findContact: + print("연락처에서 찾을 이름을 입력해주세요 : ", terminator: "") + guard let inputValue = readLine() else { + continue + } + findContact(inputName: inputValue) + continue + case .exit: + isMenuInputError = true + print("\n[프로그램 종료]") + } +}