Skip to content

Instantly share code, notes, and snippets.

@YutoMizutani
Last active October 25, 2018 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YutoMizutani/1c77fe25b6a103933572e0af1abf373b to your computer and use it in GitHub Desktop.
Save YutoMizutani/1c77fe25b6a103933572e0af1abf373b to your computer and use it in GitHub Desktop.
JSONからCodable化されたstructを自動生成するツールを作った話 ref: https://qiita.com/YutoMizutani/items/106cae55091f26bba641
{
"user": {
"Name": "Yuto Mizutani"
},
"lib": {
"lib-name": "JSONtoCodable",
"year": 2018,
"version": "1.0.2",
"released": "2018-09-22"
},
"text": "Hello, world!!"
}
public struct Result: Codable {
public let user: User
public let lib: Lib
public let text: String
public struct User: Codable {
public let name: String
private enum CodingKeys: String, CodingKey {
case name = "Name"
}
}
public struct Lib: Codable {
public let libName: String
public let year: Int
public let version: String
public let released: String
private enum CodingKeys: String, CodingKey {
case libName = "lib-name"
case year
case version
case released
}
}
}
$ brew tap YutoMizutani/jc
$ brew install jc
$ curl https://httpbin.org/get | jc
$ curl https://httpbin.org/get | jc > Result.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment