Questions tagged [codable]

Use this tag only for questions directly pertaining to the Swift Codable protocol introduced in Swift 4.

Serialization / deserialization protocol composed of Encodable and Decodable protocols. Introduced in Swift 4.

References

1568 questions
-1
votes
2 answers

Non-nominal type 'T' does not support explicit initialization Codable

I am trying to create a Response Base to contain API request but I get error Non-nominal type 'T' does not support explicit initialization when using codable. This used to work with a third party library but I am swapping out old data for new…
King
  • 1,885
  • 3
  • 27
  • 84
-1
votes
2 answers

Ignore wrapping keys in Codable

I'm getting a JSON that looks like this: { looks = ( { ... look object } ); query = ( ... array of strings ); slices = ( ( …
nandodelauni
  • 291
  • 1
  • 10
-1
votes
1 answer

How to create model for this json with codable

I have the below json and I want to create model for the json with codable. { id = 1; name = "abc"; empDetails = { data = [{ address = "xyz"; ratings = 2; "empId" = 6; "empName" = "def"; }]; …
iOSDev
  • 326
  • 2
  • 10
-1
votes
1 answer

How to decode a nested JSON struct with dynamic number of nested levels?

I can receive a JSON file with variable number of nested fields, like for example this: { "id": "field1", "values": [{ "1": [{ "11": ["111", "112"], "12": ["121", "122"] }], "2": [{ "21": ["211", "212"], "22": ["221",…
AppsDev
  • 12,319
  • 23
  • 93
  • 186
-1
votes
1 answer

Is it possible to declare generics inside Decodable model

Here is my model class struct ErrorData: Decodable { let code : Int let message : String let data : [ErrorDataFields] } i want to have ErrorDataFields to be array and object like struct ErrorData: Decodable { let code : Int …
Midhun Narayan
  • 829
  • 2
  • 9
  • 26
-1
votes
3 answers

Codable with Generics Swift 5

I am creating a generic post body for my API's call, my post body is mostly same except the data parameter which is different for different API calls data acts like filler for different requirements, few below JSON post body. Example 1: { …
Rein rPavi
  • 3,368
  • 4
  • 22
  • 32
-1
votes
1 answer

CGSize Coding/Decoding

I want to encode and decode CGSize data type in Swift and store it in a Dictionary, but am not able to find any sample code how to do it. I tried this but it gives error: let size = CGSize(width: Int(100), height: Int(50)) dictionary["size"] =…
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
-1
votes
2 answers

How to validate struct value modified or removed

Based on server response I have created this struct items now the value changed in server how to validate those in struct. Example yearValue replaced with eraValue. How the frontend should handle the pair is modified or removed. //Mark:- Time…
KkMIW
  • 1,092
  • 1
  • 17
  • 27
-1
votes
2 answers

Is there any way I can parse the JSON response array with decoder and append it within an array?

This is my JSON response: { "0": 200, "success": true, "response": [ { "id": 89, "fkuser_id": 17, "assessee_year_from": "2019", "assessee_year_to": "2020", "section_822BB": "n", "assessee_name":…
-1
votes
1 answer

adding a codable model to realm swift

I am trying to add a Codable model to a realm DB. The model works and values are passed from an API call how ever, I want to create a Array in my Realm DB so when I hit a save button, the Model is added to DB. how ever I get this error for my create…
King
  • 1,885
  • 3
  • 27
  • 84
-1
votes
1 answer

Cannot automatically synthesize 'Encodable' because 'Error' does not conform to 'Encodable'

Hi we are using codeble in our Api management layer, we are trying to set up models with codables and decodables, in one case we have Error in our response model, how can we handle that here is the sample code struct Address : Codable { …
Afsara
  • 1,411
  • 3
  • 13
  • 31
-1
votes
1 answer

FetchJson stopped he’s work for no reason

I am getting data from news API. Everything was working like 40+ times then something happened and nothing was working. After I turn on mac on next day it worked a few times and now again doesn’t, I don't know why is this. please help, code is below…
-1
votes
3 answers

Swift Codable: Array of Array having Dictionaries

I have a JSON object, I cannot figure out how to access the exclude_list in given JSON. {"variants": {"variant_groups": [ { "group_id":"1", "name":"Crust", …
Rocky
  • 2,903
  • 1
  • 22
  • 26
-1
votes
1 answer

Parsing array with {"Name": String, "Value": String} structure in Swift 4

I need to parse in Swift a data structure similar to this (based on a JSON): [ { "Name": "uniquename", "Value": "John" }, { "Name": "locale", "Value": "UK" }, ] I stored this node in a struct like this struct Rowset :…
Nicola Bertelloni
  • 333
  • 1
  • 3
  • 17
-1
votes
1 answer

Swift: Enum codable how to get raw value

I have a class with a field type ID (enum class), both are codable, I can not read the raw value of the enum, what should I implement other My code: struct Answer: Codable { let id: ID? let message: String? enum CodingKeys: String,…
Mickael Belhassen
  • 2,970
  • 1
  • 25
  • 46
1 2 3
99
100