Conversation
There was a problem hiding this comment.
아니 수빈씌,,, 너무 잘하셨는데요 ,,, , ,, , ,,, 말을 잃었다..
친절하게 화면전환 설명해준 것도 넘 고마워 >,< 최고얌💜
그리고 나는 PathErr에서는 에러메시지를 안받아오고 requestFail일 때만 에러메시지를 받아왔어!
보통 path err는 경로 에러라서 path err가 발생한다면 우리가 요청 보내는 경로가 잘못된 경우잖아!!
그래서 path err에대해서는 응답문이 request err처럼 여러가지로 나눠져서 오지 않는 편이라 (서버에서도 path err에 관한 에러 핸들링은 한번만 하는 경우가 많아가지고,,) 그리고 msg를 받아와서 alert로 사용자에게 띄울 필요가 없으니까 (클라 단에서만 알아두면 될 에러라고 생각돼서 print문으로만 식별해도 괜찮다고 생각해써!)
그래서 request err일때만 에러 메시지를 받아와줬어!
이렇게 하는 방법도 있다구 알려주고 싶어서!!! :)
private func judgeData(status: Int, data: Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<SignResultData>.self, from: data) else {
return .pathErr }
switch status {
case 200:
return .success(decodedData.data ?? "None-Data")
case 400:
return .requestErr(decodedData.message)
case 404:
return .pathErr
case 500:
return .serverErr
default:
return .networkFail
}
}
수빈이 고생해써 이번주두 👍🏻
| /// Main 스토리보드의 LoginVC -> Main 스토리보드의 SuccessVC | ||
| guard let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "SuccessVC") as? SuccessVC else {return} | ||
|
|
||
| nextVC.message = self.nameTextField.text |
There was a problem hiding this comment.
요부분은 SuccessVC에서 UserDefaults로 값 설정해주니까 없어도 될 것 같아!! 🤗🤗
There was a problem hiding this comment.
if문으로 케이스 나눠 준거 넘 좋다 슨배..!
나는 방금 리펙터링 하면서 extension 파일으로 따로 빼주고 해봤는데,, 그렇게 하니까 넘 편하드랑..!
아래 처럼 요로코롬 extension 빼주고
extension UIViewController {
func makeAlert(title : String,
message : String,
okAction : ((UIAlertAction) -> Void)? = nil,
completion : (() -> ())? = nil)
{
let alertViewController = UIAlertController(title: title, message: message,
preferredStyle: .alert)
let okAction = UIAlertAction(title: "확인", style: .default, handler: okAction)
alertViewController.addAction(okAction)
self.present(alertViewController, animated: true, completion: completion)
}
}사용하는 부분에서 요로코롬 okAction에 성공인 경우, 실패인 경우 나눠줬엉!
//성공인 경우
self.makeAlert(title: "로그인", message: response.message, okAction: { _ in
guard let welcomeVC = self.storyboard?.instantiateViewController(withIdentifier: "WelcomeVC") as? WelcomeVC else {return}
welcomeVC.modalPresentationStyle = .fullScreen
self.present(welcomeVC, animated: true, completion: nil)
})
//실패인 경우
self.makeAlert(title: "로그인", message: response.message, okAction: { _ in
setTextFieldEmpty() //요건 실패했을때 textfield를 비워주고싶어서 내가 짠 함수..!
})| if let userData = response.data { | ||
| self.showAlert(title: "로그인", message: response.message) | ||
| } | ||
| UserDefaults.standard.set(nameTextField.text, forKey: "userName") |
There was a problem hiding this comment.
💡 지은의 팁
UserDefaults의 key를 코드 내에서 직접 설정해 줄 경우, 나중에 내가 비슷한 경우에 사용하려고 저장해둔 key value가 있을텐데.. 하고 찾아다니는 일이 발생하게 돼..! 엄청 헷갈리구.. (이건 내 경험담..!)
지금 같은 경우도 1. 로그인 성공시 2. 회원가입 성공시 3. 로그인/회원가입 확인뷰에서 동일한 키를 사용하고 있지! 이 작업들의 개수가 늘어나게 되면 일일이 관리해주고 찾아다니는게 어려워지게 될거야
그래서 Extension으로 Userdefaults의 key값들을 빼서 관리하는 걸 추천해!!
extension UserDefaults {
// UserDefaults key value가 많아지면 관리하기 어려워지므로 enum 'Keys'로 묶어 관리
enum Keys {
static var loginUserName = "loginUserName"
}
}
| func showAlert(title: String, message: String, okAction: ((UIAlertAction) -> Void)? = nil) { | ||
| let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) | ||
| let okAction = UIAlertAction(title: "확인", style: .default, handler: { action in | ||
| /// 서버에서 받은 message가 "회원 가입 성공"일 때만 화면 전환 | ||
| if message == "회원 가입 성공" { | ||
| /// present 화면 전환 | ||
| /// Main 스토리보드의 SignupVC -> Main 스토리보드의 SuccessVC | ||
| guard let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "SuccessVC") as? SuccessVC else {return} | ||
| nextVC.message = self.nameTextField.text | ||
| nextVC.modalPresentationStyle = .fullScreen | ||
| self.present(nextVC, animated: true, completion: nil) | ||
| } | ||
| }) | ||
| alert.addAction(okAction) | ||
| present(alert, animated: true) | ||
| } |
There was a problem hiding this comment.
이 부분을 extension으로 빼서 구현해도 좋을 것 같아요 로그인, 회원가입 둘 다에서 쓰이니까!! 👍🏻
hyun99999
left a comment
There was a problem hiding this comment.
수고하셨습니다! 풀리퀘의 화면전환을 설명해주신게 너무 인상적이네요 ? ^^
| private func isInvalidLoginData(data: Data) -> NetworkResult<Any> { | ||
| let decoder = JSONDecoder() | ||
| guard let decodedData = try? decoder.decode(LoginDataModel.self, from: data) else {return .networkFail} | ||
| return .pathErr(decodedData) | ||
| } | ||
| } |
There was a problem hiding this comment.
networkFail 보다는 디코딩을 실패한다=잘못된경로로 요청해서 데이터가 넘어오지 않았다.or 데이터가 형식이 맞지 않는다
이기 때문에 .pathErr 가 어울리는거 같아요!
그리고 .pathErr 는 requestErr 로 바꿔서 경로는 맞지만 요청에 대한 에러를 다룰 수 있도록 하면 좋을거 같아요!
제 코리를 보셨다니까.. 넵.. 요기까지만 남기겠습니당~
| @IBAction func touchUpProfileButton(_ sender: Any) { | ||
| /// present 화면 전환 | ||
| /// YoutubeMain 스토리보드의 HomeVC -> Main 스토리보드의 navigationController | ||
| let storyboard = UIStoryboard.init(name: "Main", bundle: nil) | ||
| guard let navi = storyboard.instantiateViewController(withIdentifier: "MainNavi") as? UINavigationController else {return} | ||
|
|
||
| navi.modalPresentationStyle = .fullScreen | ||
| present(navi, animated: true, completion: nil) | ||
| } |
There was a problem hiding this comment.
수빈선배 덕분에... 난 구원받앗어...
이방법도 좋은데 현규슨배께서 Scene Delegate에서 RootView 설정이랑, NavigationController 설정해주고 스보 없이 코드로 짜는 방법이 있대유,,, 정확히는 잘 모르지만 그런 방법이 있대유,,, 하지만 난 모대.
hellozo0
left a comment
There was a problem hiding this comment.
수빈양.... 그림까지 그려주고 넘 친절한거 아잉교..?
수빈양의 코드를 보고 넘 많이 배운다... 나 여태 세미나 하면서 궁금했던 NavigationController에 VC안 만들고 연결하는걸 수빈양 덕에 한달만에 깨달았어... 당신은 나의 은인이오,,,
서버 질문까지 받아줘서 고마웡!!!!!!!
| @IBAction func touchUpProfileButton(_ sender: Any) { | ||
| /// present 화면 전환 | ||
| /// YoutubeMain 스토리보드의 HomeVC -> Main 스토리보드의 navigationController | ||
| let storyboard = UIStoryboard.init(name: "Main", bundle: nil) | ||
| guard let navi = storyboard.instantiateViewController(withIdentifier: "MainNavi") as? UINavigationController else {return} | ||
|
|
||
| navi.modalPresentationStyle = .fullScreen | ||
| present(navi, animated: true, completion: nil) | ||
| } |
There was a problem hiding this comment.
수빈선배 덕분에... 난 구원받앗어...
이방법도 좋은데 현규슨배께서 Scene Delegate에서 RootView 설정이랑, NavigationController 설정해주고 스보 없이 코드로 짜는 방법이 있대유,,, 정확히는 잘 모르지만 그런 방법이 있대유,,, 하지만 난 모대.
| /// Main 스토리보드의 LoginVC -> Main 스토리보드의 SuccessVC | ||
| guard let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "SuccessVC") as? SuccessVC else {return} | ||
|
|
||
| nextVC.message = self.nameTextField.text |
There was a problem hiding this comment.
if문으로 케이스 나눠 준거 넘 좋다 슨배..!
나는 방금 리펙터링 하면서 extension 파일으로 따로 빼주고 해봤는데,, 그렇게 하니까 넘 편하드랑..!
아래 처럼 요로코롬 extension 빼주고
extension UIViewController {
func makeAlert(title : String,
message : String,
okAction : ((UIAlertAction) -> Void)? = nil,
completion : (() -> ())? = nil)
{
let alertViewController = UIAlertController(title: title, message: message,
preferredStyle: .alert)
let okAction = UIAlertAction(title: "확인", style: .default, handler: okAction)
alertViewController.addAction(okAction)
self.present(alertViewController, animated: true, completion: completion)
}
}사용하는 부분에서 요로코롬 okAction에 성공인 경우, 실패인 경우 나눠줬엉!
//성공인 경우
self.makeAlert(title: "로그인", message: response.message, okAction: { _ in
guard let welcomeVC = self.storyboard?.instantiateViewController(withIdentifier: "WelcomeVC") as? WelcomeVC else {return}
welcomeVC.modalPresentationStyle = .fullScreen
self.present(welcomeVC, animated: true, completion: nil)
})
//실패인 경우
self.makeAlert(title: "로그인", message: response.message, okAction: { _ in
setTextFieldEmpty() //요건 실패했을때 textfield를 비워주고싶어서 내가 짠 함수..!
})
📌 관련 이슈
closed #9
📌 변경 사항 및 이유
📌 PR Point
가장 고민됐던 부분은 pathErr일 때 메세지를 받아와서 띄워주는 부분이었는데
networkRestult에서 pathErr도 값을 받아올 수 있게 해서 구성했습니다..
또 하다보니 이 전에 연결했던 화면 전환이랑 present.. push ... 막 꼬이는 것 같아서 혼란스러웠는데

아래처럼 구성했슴다 제가 하다보니 머릿속도 막 꼬이는 것 같아서 그려봤는데 이해하는데에 쪼금이라도 도움이 되시라구 올려봅니다..
📌 참고 사항
서버 너무 어려워서 눈물이 주륵주륵 나요
일단 어째저째 굴러가도록 하긴 했는데 다소 얼렁뚱땅한 것 같네여.. 이게 맞나..
더 좋은 방법이나 이상한 부분이나 맘에 안드는 부분 등등이 있다면 다 코멘트 남겨주시면 제가... 열심히 보겠슴니다