Skip to content
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

[REFACTOR] #61 - NetworkModel 옵셔널변수 설정 및 예외처리 #70

Merged
merged 1 commit into from
Nov 19, 2021

Conversation

hyun99999
Copy link
Member

🌴 PR 요약

🌱 작업한 브랜치

🌱 작업한 내용

  • 옵셔널 변수가 필요한 경우 수정
  • key-value 가 서버에서 넘어오지 않을 경우 기본값 설정.(예외처리)
  • 예외처리를 위해서 모든 변수를 옵셔널 변수로 선언하게 되면 옵셔널체이닝을 통해서 사용하는것은 문제가 안되지만 코드적으로 이 변수는 있을수도 없을수도 있는 값이 아니라 있어야하는 값인데 옵셔널로 선언하는 것이 아니라고 생각을 했습니당
  • key-value 가 넘어오지 않는 경우는 옵셔널 변수는 try? 문으로 디코딩을 먼저해서 nil 값을 할당하거나 옵셔널 변수가 아닌경우는 -1, "" 와 같이 기본값을 할당해주었습니다.

📮 관련 이슈

@hyun99999 hyun99999 added Hyungyu 🐯 현규 교수님 작업 Refactor 로직은 변경하지 않고, 기존의 코드를 개선하는 리펙토링 labels Nov 18, 2021
@hyun99999 hyun99999 self-assigned this Nov 18, 2021
Copy link
Member

@mini-min mini-min left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

서버때문에 교수님 고생이 많으시네요ㅠㅜㅠㅜㅠㅜ

Comment on lines 10 to +22
// MARK: - User

struct User: Codable {
let userID: String

enum CodingKeys: String, CodingKey {
case userID = "userId"
}

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
userID = (try? values.decode(String.self, forKey: .userID)) ?? ""
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그냥 이렇게 빼주셨군요 감사합니다 ㅜㅜㅜ

Comment on lines +36 to 51

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
cardID = (try? values.decode(String.self, forKey: .cardID)) ?? ""
background = (try? values.decode(String.self, forKey: .background)) ?? ""
title = (try? values.decode(String.self, forKey: .title)) ?? ""
name = (try? values.decode(String.self, forKey: .name)) ?? ""
birthDate = (try? values.decode(String.self, forKey: .birthDate)) ?? ""
age = (try? values.decode(String.self, forKey: .age)) ?? ""
mbti = (try? values.decode(String.self, forKey: .mbti)) ?? ""
instagram = (try? values.decode(String.self, forKey: .instagram))
linkName = (try? values.decode(String.self, forKey: .linkName))
link = (try? values.decode(String.self, forKey: .link))
cardDescription = (try? values.decode(String.self, forKey: .cardDescription))
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하👍🏻

Copy link
Member

@dlwns33 dlwns33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨씁니당 교수님 짱

@hyun99999 hyun99999 merged commit 1b688fa into TeamNADA:develop Nov 19, 2021
@hyun99999 hyun99999 deleted the feature/#61 branch November 19, 2021 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hyungyu 🐯 현규 교수님 작업 Refactor 로직은 변경하지 않고, 기존의 코드를 개선하는 리펙토링
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR] NetworkModel 옵셔널변수 설정 및 예외처리
3 participants