Comments (1)
Baby can not infer all the Any?
type and data
which is a array with different type object in it.
You can modify the output struct as follow:
- Specify the type of
limit
,transform
,columnIndex
,collapse
andorder
. - Create a
MyData
enum to wrap thedata
's object (It's a little bit complicated).
Such as:
enum DecodingError: Error {
case typeMismatch
}
enum MyData: Codable {
case string(String)
case double(Double)
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let x = try? container.decode(String.self) {
self = .string(x)
return
}
if let x = try? container.decode(Double.self) {
self = .double(x)
return
}
throw DecodingError.typeMismatch
}
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .string(let x):
try container.encode(x)
case .double(let x):
try container.encode(x)
}
}
}
struct Aluminum: Codable {
struct Dataset: Codable {
let id: Int
let datasetCode: String
let databaseCode: String
let name: String
let description: String
let refreshedAt: Date
let newestAvailableDate: Date
let oldestAvailableDate: Date
let columnNames: [String]
let frequency: String
let type: String
let premium: Bool
let limit: Int?
let transform: Int?
let columnIndex: Int?
let startDate: Date
let endDate: Date
let data: [[MyData]]
let collapse: Int?
let order: Int?
let databaseId: Int
private enum CodingKeys: String, CodingKey {
case id
case datasetCode = "dataset_code"
case databaseCode = "database_code"
case name
case description
case refreshedAt = "refreshed_at"
case newestAvailableDate = "newest_available_date"
case oldestAvailableDate = "oldest_available_date"
case columnNames = "column_names"
case frequency
case type
case premium
case limit
case transform
case columnIndex = "column_index"
case startDate = "start_date"
case endDate = "end_date"
case data
case collapse
case order
case databaseId = "database_id"
}
}
let dataset: Dataset
}
Baby can not guarantee that it is always correct, but it can save your time to create the base struct.
from baby.
Related Issues (20)
- 大佬,介个解析出来会少字母撒。 HOT 4
- property map could Generate two Sturcts? HOT 1
- crash with large data set, app will not reopen HOT 3
- Realm support HOT 1
- Flat Json, CoreData, support Optional and Requeried fields
- [Feature Suggestion] Allow using `convertFromSnakeCase` strategy instead of CodingKeys HOT 2
- 能否增加个可选功能, 来生成 init(from decoder: Decoder) throws 的实现 HOT 2
- Hmmm. What should these do... HOT 6
- CB not creating the outer init correctly. HOT 4
- The JSON crashing the Shared Baby. HOT 1
- Snake to Camel works in reverse
- Format button fails.
- 能否增加一个可选功能,驼峰开关
- 某些字符串值被错误的映射为 URL HOT 2
- not parsing right HOT 8
- Property name conflict with swift keywords HOT 2
- 这种嵌套的 JSON 无法生成正确的 Model 吗? HOT 5
- 商店版弹出 write a review 后再也无法关闭,重装依旧。 HOT 4
- Can't hide `Write a review`. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from baby.