-
Notifications
You must be signed in to change notification settings - Fork 21
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
hope to support inheritance #8
Comments
Hey, do you have any issue I can replicate ? |
yes, demo codeclass SuperClass {
var name: String?
var sex: String?
var age: Int?
}
class SubClass: SuperClass, Codable {
var a: String?
var b: Int?
enum CodingKeys: String, KeyedKey {
case a, b
}
}
private let jsonString = """
{
"name": "John",
"age": 18,
"sex": "F",
"a": "aa",
"b": 100,
"qqqq": {
".greeting": "Hallo world",
"details": {
"description": "Its nice here"
}
},
"longitude": 3.2,
"latitude": 3.4
}
"""
func testCodable() throws {
let jsonData = jsonString.data(using: .utf8)!
let model = try SubClass.keyed.fromJSON(jsonData)
print(model)
}
result
|
Thank you for detailed description. I'll look on that but it may be hard to support - it's known issue of Codables and it's not related with KeyedCodables. What do you think to use composition instead of inheritance? Using @Flat you will use the same JSON format. Your example will look like that.
|
@dgrzeszczak amazing, It fulfills my needs, thanks. |
No description provided.
The text was updated successfully, but these errors were encountered: