-
Notifications
You must be signed in to change notification settings - Fork 0
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/week4 API 연동하기 #7
base: main
Are you sure you want to change the base?
Conversation
- 굳이 파일 분리가 필요없음. 파일 통합 - 파일 구조 변경 - DTO 추가 - addSubviews extension추가 - logIn 함수 JSONDecoder 사용
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 { | ||
let logInResponse = try JSONDecoder().decode(LogInResponse.self, from: data) | ||
let token = logInResponse.result.token | ||
TokenManager.shared.saveToken(token) | ||
completion(.success(logInResponse)) | ||
} catch { | ||
completion(.failure(.unknownError)) | ||
} |
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문 쓰신 거 좋네요!
} | ||
|
||
let headers: HTTPHeaders = [ | ||
"Content-Type": "application/json", |
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.
저는 그냥 ["token": "(token)"] 이렇게만 작성했는데 별 문제 없이 괜찮았어요!
username: userNameTextField.text!, // optional처리 | ||
password: userPasswordTextField.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.
강제 언래핑보다는 guard let으로 옵셔널 바인딩 처리해주거나
아니면 그냥 userNameTextField.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.
오 토큰매니저 클래스를 따로 만드는 방법이 있었네요..
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.
노력하는 모습이멋져👍
@@ -6,7 +6,7 @@ | |||
// | |||
|
|||
import UIKit | |||
|
|||
//$0, $1, $2 ... - param을 축약 |
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.
...? 이걸 왜 여기다?
/// public let result: Result<Success, Failure> | ||
/// Alamofire의 data response에는 result 프로퍼티가 존재하는데, 해당 프로퍼티는 Result<Success, Failure> 타입임! | ||
/// 이 말은, 타입이 다른 함수에서 리턴되어 넘어갈 때, success로 넘어갈 수 있고 failure로 넘어갈 수 있다는 것 | ||
/// 그리고 그 안에는 우리가 원하는 결과값들이 존재한다. | ||
/// Result<Bool, NetworkError> : 성공 시 Bool, 실패 시 NetworkError값을 return 하게 됨. | ||
/// Success 하면 Bool 값을, Failure 하면 NetworkError를 리턴하겠다는 뜻 | ||
/// Success에는 원하는 타입이 올 수 있고, Failure에는 Error 프로토콜이 채택된 것이 리턴될 수 있도록 되어야 함 | ||
switch response.result { |
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.
배우고 기록하는 열정 👍
|
||
import UIKit | ||
|
||
class LogInViewController: UIViewController { //hee eun |
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.
고생하셨습니다!!
|
||
private func setLayout() { | ||
// SnapKit을 통해 오토레이아웃 코드 변경하기. | ||
NSLayoutConstraint.activate( |
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.
SnapKit import 하셨는데 �SnapKit으로 레이아웃을 설정하지 않으신 이유가 궁금합니다!
} | ||
} | ||
|
||
extension ChartViewController: UITableViewDelegate{} |
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.
작성한 코드가 없다면 delegate는 삭제해도 좋을 것 같습니다:D
|
||
import Foundation | ||
|
||
class TokenManager { |
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.
오호 TokenManager로 토근을 관리하�셨군요!! 흥미롭습니다
let token = logInResponse.result.token | ||
TokenManager.shared.saveToken(token) | ||
completion(.success(logInResponse)) | ||
} catch { |
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.
잘 몰라서 그러는데, .success 케이스 안에서도 에러가 발생하는 경우가 있나요? 있다면 어떤 경우인지 궁금합니다!
API 연동하기
이슈
작업 내용
Simulator
추가 구현 필요 부분