We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enum ValidationError: Int, Error { case emptyString = 401 case invalidInt = 402 case invalidDate = 403 } func validateUserError(text: String) throws -> Bool { guard !(text.isEmpty) else { throw ValidationError.emptyString } guard Int(text) != nil else { print("숫자가 아닙니다.") throw ValidationError.invalidInt } //사용자가 입력한 값이 날짜 형태로 변환이 되는 숫자인지 아닌지 guard chectDateFormat(text: text) else { print("날짜 형태가 아닙니다.") throw ValidationError.invalidDate } return true } do { let result = try validateUserInput(text: "20211101") } catch ValidationError.emptyString { print("값이 비어 있습니다.") } catch ValidationError.invalidInt { print("숫자 값이 아닙니다.") } catch ValidationError.invalidDate { print("날짜 값이 아닙니다.") } //또는 do { let result = try validateUserInput(text: "20211101") } catch { switch error { case ValidationError.invalidDate: print("날짜 값이 아닙니다." ValidationError.invalidDate.rawValue) case ValidationError.emptyString: print("값이 비어 있습니다.") case ValidationError.invalidInt: print("숫자 값이 아닙니다.") } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
do-try catch
if - else 문
The text was updated successfully, but these errors were encountered: