Skip to content

JSON 모델 파싱을 매크로로 간단하게

Notifications You must be signed in to change notification settings

WhiteHyun/DTOMacro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON 모델을 디코딩할 때 간편하게 해주는 매크로

// 전
struct Model: Codable {
  let userInformation: UserInfo
  let totalUsers: Int
  
  enum CodingKeys: String, CodingKey {
    case userInformation = "user_information"
    case totalUsers = "total_users"
  }
}

struct UserInfo: Codable {
  let isAdmin: Bool
  let postCount: Int
  let isBanned: Bool
  
  enum CodingKeys: String, CodingKey {
    case isAdmin = "is_admin"
    case postCount = "post_count"
    case isBanned = "is_banned"
  }
}

// 매크로 사용 후
@DTO
struct Model {
  @Property(key: "user_information") let userInfo: UserInfo
  @Property(key: "total_users") let totalUsers: Int
}

@DTO
struct UserInfo {
  @Property(key: "is_admin") let isAdmin: Bool
  @Property(key: "post_count") let postCount: Int
  @Property(key: "is_banned") let isBanned: Bool
}

About

JSON 모델 파싱을 매크로로 간단하게

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages