-
Notifications
You must be signed in to change notification settings - Fork 6
[Lv_3~4] 기능 구현 완료 #17
New issue
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
base: jeff-0324
Are you sure you want to change the base?
Conversation
Crois0509
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
왜인지 일부 파일들이 보이지 않지만... 멋진 코드 잘 봤습니다!!
코드의 역할 분담이 잘 이루어져 있는 것 같아요!!
완성까지 파이팅입니다!!
| while answerArray.count != 3 { | ||
| let randomValue = getRandomValue() | ||
| if !answerArray.contains(randomValue) { | ||
| answerArray.append(randomValue) | ||
| } | ||
| if answerArray[0] == 0 { | ||
| answerArray.removeFirst() | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while문의 조건을 !=3 으로 주셨네요! 코드 로직상 그럴 일은 없겠지만 만약 answerArray.count가 4가 되면 어떻게 될까요??
아마 while문을 영원히 빠져나오지 못할 것 같아요!!
비교연산자가 절대 틀린 것은 아니지만 이 경우 < 3으로 3과 같거나 커지면 멈추도록 하는게 더욱 안전할 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 그렇죠! 그 부분 수정해서 다시 올렸습니다.
감사합니다 ㅎ
ericKwon95
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생 많으셨습니다~~!! 짱짱입니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do catch 활용 좋습니다!
catch시에 원하는 문장을 출력하고자 하는 의도를 유지하고 코드를 줄일 수 있는데요,
LocalizedError 프로토콜을 활용해 각 에러마다 description을 제공할 수 있는 점 공유드립니다~!
enum BaseballGameError {
enum InputError: LocalizedError {
case notString
case countNotMatching
case duplicatedNumber
case zeroDetected
case zeroIsFirst
case notInteger
case levelError
case invalidInput
var errorDescription: String? {
switch self {
case .notString:
return "문자열 입력이 아닙니다."
case .duplicatedNumber:
return "중복된 숫자가 있습니다."
case .countNotMatching:
return "입력 수의 갯수가 다릅니다."
case .zeroDetected:
return "0은 입력할 수 없습니다."
case .zeroIsFirst:
return "0이 가장 처음 에 올 수 없습니다."
case .notInteger:
return "정수 입력이 아닙니다."
case .levelError:
return "유효하지 않은 레벨입니다. 1~6까지를 선택해주세요."
case .invalidInput:
return "잘못된 입력입니다."
}
}
}
}이렇게 선언하시고, 아래와 같이 출력할 수 있어요
do {
// ...
} catch let error {
print(error.localizedDescription)
}- 그러면 위와 같이 간단하게 사용할 수 있습니다~!
| print("환영합니다! 원하시는 번호를 입력해주세요") | ||
|
|
||
| // 보기 선택이 이루어지도록 구현 | ||
| while !range.contains(select) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
입력값이 range를 벗어나면 while문이 종료되도록 구현하셨군요!
잘못된 입력일 경우의 예외처리도 함께 고민해 보시면 정말 좋을 것 같아요~~!
| let userValue = GetUserValue() | ||
| lazy var checkAnswer = CheckAnswer(getAnswer: answer, getUserValue: userValue) | ||
| var endPoint = 0 | ||
| static var endPoint = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요 변수를 static으로 선언하신 이유가 궁금합니다!
No description provided.