I need to "replicate" entiry, which returns from the remote web API service in JSON. It looks like this:
{ "field1": "some_id", "entity_name" = "Entity1" "field2": "some name", "details1": [{ "field1": 11, "field2": "some value", "data": { "key1": "value1", "key2": "value2", "key3": "value3", // any other, unknown at compile time keys } }], "details2": { "field1": 13, "field2": "some value2" } }
Here is my attempt:
struct Entity1 { struct Details1 { let field1: UInt32 let field2: String let data: [String: String] } struct Details2 { let field1: UInt32 let field2: String } let field1: String static let entityName = "Entity1" let field2: String let details1: [Details1] let details2: Details2 }
- It is a good idea to use structures instead of classes for this purpose. How is mine?
- Is there any way to define a nested structure or class, say Details1, and create a variable at the same time?
Like this:
json swift
user266003
source share