-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/#9 assignment 4 #12
Conversation
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.
์๋ ์๋น์,,, ๋๋ฌด ์ํ์
จ๋๋ฐ์ ,,, , ,, , ,,, ๋ง์ ์์๋ค..
์น์ ํ๊ฒ ํ๋ฉด์ ํ ์ค๋ช
ํด์ค ๊ฒ๋ ๋ ๊ณ ๋ง์ >,< ์ต๊ณ ์๐
๊ทธ๋ฆฌ๊ณ ๋๋ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ถ๋ถ์ SuccessVC์์ UserDefaults๋ก ๊ฐ ์ค์ ํด์ฃผ๋๊น ์์ด๋ ๋ ๊ฒ ๊ฐ์!! ๐ค๐ค
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐ก ์ง์์ ํ
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด ๋ถ๋ถ์ extension์ผ๋ก ๋นผ์ ๊ตฌํํด๋ ์ข์ ๊ฒ ๊ฐ์์ ๋ก๊ทธ์ธ, ํ์๊ฐ์ ๋ ๋ค์์ ์ฐ์ด๋๊น!! ๐๐ป
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.
์๊ณ ํ์ จ์ต๋๋ค! ํ๋ฆฌํ์ ํ๋ฉด์ ํ์ ์ค๋ช ํด์ฃผ์ ๊ฒ ๋๋ฌด ์ธ์์ ์ด๋ค์ ? ^^
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
์๋น์ ๋ฐฐ ๋๋ถ์... ๋ ๊ตฌ์๋ฐ์์ด...
์ด๋ฐฉ๋ฒ๋ ์ข์๋ฐ ํ๊ท์จ๋ฐฐ๊ป์ Scene Delegate์์ RootView ์ค์ ์ด๋, NavigationController ์ค์ ํด์ฃผ๊ณ ์ค๋ณด ์์ด ์ฝ๋๋ก ์ง๋ ๋ฐฉ๋ฒ์ด ์๋์ ,,, ์ ํํ๋ ์ ๋ชจ๋ฅด์ง๋ง ๊ทธ๋ฐ ๋ฐฉ๋ฒ์ด ์๋์ ,,, ํ์ง๋ง ๋ ๋ชจ๋.
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.
์๋น์.... ๊ทธ๋ฆผ๊น์ง ๊ทธ๋ ค์ฃผ๊ณ ๋ ์น์ ํ๊ฑฐ ์์๊ต..?
์๋น์์ ์ฝ๋๋ฅผ ๋ณด๊ณ ๋ ๋ง์ด ๋ฐฐ์ด๋ค... ๋ ์ฌํ ์ธ๋ฏธ๋ ํ๋ฉด์ ๊ถ๊ธํ๋ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋น์ ๋ฐฐ ๋๋ถ์... ๋ ๊ตฌ์๋ฐ์์ด...
์ด๋ฐฉ๋ฒ๋ ์ข์๋ฐ ํ๊ท์จ๋ฐฐ๊ป์ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ... ๋ง ๊ผฌ์ด๋ ๊ฒ ๊ฐ์์ ํผ๋์ค๋ฌ์ ๋๋ฐ
์๋์ฒ๋ผ ๊ตฌ์ฑํ์ด๋ค ์ ๊ฐ ํ๋ค๋ณด๋ ๋จธ๋ฆฟ์๋ ๋ง ๊ผฌ์ด๋ ๊ฒ ๊ฐ์์ ๊ทธ๋ ค๋ดค๋๋ฐ ์ดํดํ๋๋ฐ์ ์ชผ๊ธ์ด๋ผ๋ ๋์์ด ๋์๋ผ๊ตฌ ์ฌ๋ ค๋ด ๋๋ค..
๐ ์ฐธ๊ณ ์ฌํญ
์๋ฒ ๋๋ฌด ์ด๋ ค์์ ๋๋ฌผ์ด ์ฃผ๋ฅต์ฃผ๋ฅต ๋์
์ผ๋จ ์ด์งธ์ ์งธ ๊ตด๋ฌ๊ฐ๋๋ก ํ๊ธด ํ๋๋ฐ ๋ค์ ์ผ๋ ๋ฑ๋ ํ ๊ฒ ๊ฐ๋ค์ฌ.. ์ด๊ฒ ๋ง๋..
๋ ์ข์ ๋ฐฉ๋ฒ์ด๋ ์ด์ํ ๋ถ๋ถ์ด๋ ๋ง์ ์๋๋ ๋ถ๋ถ ๋ฑ๋ฑ์ด ์๋ค๋ฉด ๋ค ์ฝ๋ฉํธ ๋จ๊ฒจ์ฃผ์๋ฉด ์ ๊ฐ... ์ด์ฌํ ๋ณด๊ฒ ์ด๋๋ค