Comments (4)
@dgrzeszczak amazing, It fulfills my needs, thanks.
from keyedcodable.
Hey, do you have any issue I can replicate ?
from keyedcodable.
yes, keyedCoable
seem to don't support inheritance of class
demo code
class 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
(CodableTests.SubClass) model = 0x00006000003a4180 {
CodableTests.SuperClass = {
name = nil
sex = nil
age = nil
}
a = "aa"
b = 100
}
from keyedcodable.
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.
class SuperClass: Codable {
var name: String?
var sex: String?
var age: Int?
}
class SubClass: Codable {
var a: String?
var b: Int?
@Flat var c: SuperClass // may be optional as well @Flat var c: SuperClass?
}
from keyedcodable.
Related Issues (5)
- Check Null Values HOT 2
- Bazel build HOT 2
- SPM and releases HOT 1
- Release latest version to cocoapods
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 keyedcodable.