Last active
October 25, 2018 04:03
-
-
Save YutoMizutani/1c77fe25b6a103933572e0af1abf373b to your computer and use it in GitHub Desktop.
JSONからCodable化されたstructを自動生成するツールを作った話 ref: https://qiita.com/YutoMizutani/items/106cae55091f26bba641
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"user": { | |
"Name": "Yuto Mizutani" | |
}, | |
"lib": { | |
"lib-name": "JSONtoCodable", | |
"year": 2018, | |
"version": "1.0.2", | |
"released": "2018-09-22" | |
}, | |
"text": "Hello, world!!" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ brew tap YutoMizutani/jc | |
$ brew install jc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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