decodable Questions

3

I have the Animal protocol with 2 structs that conform to it and a Farm struct which stores a list of Animals. Then, I make them all conform to Codable to store it in a file, but it throws the erro...
Diatribe asked 6/5, 2018 at 23:19

13

Solved

I'm currently working with Codable types in my project and facing an issue. struct Person: Codable { var id: Any } id in the above code could be either a String or an Int. This is the reason id...
Galitea asked 17/1, 2018 at 9:7

2

Solved

I need to decode (Decodable protocol) an imprecise decimal value correctly, from this question I understand how to properly handle the Decimal instantiation, but how can I do this when decoding? I...
Sailer asked 12/3, 2019 at 22:10

12

Solved

Why am I getting a "Type 'Bookmark' does not conform to protocol 'Decodable'" error message? class Bookmark: Codable { weak var publication: Publication? var indexPath: [Int] var locationInText...
Bessbessarabia asked 1/2, 2018 at 17:19

3

Solved

So, I have a type which looks like this: struct Identifier { let string: String } extension Identifier: Decodable { public init(from decoder: Decoder) throws { let container = try decoder.sing...
Longfellow asked 8/5, 2018 at 16:3

7

Here's my code: class LoginUserResponse : Codable { var result: String = "" var data: LoginUserResponseData? var mess: [String] = [] } public class LoginUserResponseData : Codable { var userI...
Lowbred asked 23/2, 2018 at 7:58

2

Solved

Is it possible to implement the Encodable and Decodable properties for UIColor When I try to add a Decodable extension I get an error extension UIColor : Decodable { public required init(from de...
Splanchnology asked 1/2, 2018 at 15:34

4

Solved

Found in Apple doc, that Codable protocol is composed of Encodable and Decodable. Thus, Codable = Encodable & Decodable Now, let's say I implemented below classes, class X: Codable { var n...
Gopak asked 12/3, 2020 at 10:30

1

Solved

I'm using a property wrapper to decode the strings "true" and "false" as Booleans. I also want to make the key optional. So if the key is missing from the JSON, it should be dec...
Especially asked 15/11, 2021 at 17:47

2

Solved

I was trying to connect my API data to view it in the cell but it seems that I can't get my response and it's always == nil The code below describes the Country.SWIFT // Model.SWIFT // Response.SWI...
Expend asked 12/10, 2020 at 17:46

1

Solved

In a simple project at Github I am trying to download a list of JSON objects: struct TopResponse: Codable { let data: [Top] } struct Top: Codable /*, Identifiable */ { let uid: Int let elo: Int...
Janeejaneen asked 4/5, 2021 at 15:50

2

I have a generic REST request: struct Request<T> {…} The T is the return type of the request, for example: struct Animal {…} let animalRequest = Request<Animal> let animal: Animal =...
Petree asked 11/8, 2017 at 12:15

3

Solved

I am using Codable protocol from Swift 4 first time, I am not able to understand use of decodeIfPresent from Decodable. /// Decodes a value of the given type for the given key, if present. /// //...
Susurrus asked 19/9, 2017 at 5:14

4

Solved

I am attempting to decode a JSON response from a third-party API which contains nested/child JSON that has been base64 encoded. Contrived Example JSON { "id": 1234, "attributes&quo...
Thereon asked 28/9, 2020 at 22:13

2

Solved

I'm working with CoreData and JSON parsing with Decodable following this and encountered an error at the end of the initializer saying 'self.init' isn't called on all paths before returning from in...
Unreflective asked 28/8, 2020 at 15:7

2

Solved

I am writing a program using Swift 4 and Xcode 9.2. I have faced difficulties with writing encodable class (exactly class, not struct). When I am trying to inherit one class from another, JSONEncod...
Haunted asked 13/1, 2018 at 8:28

2

I’m using Swift to try and decode JSON:API-formatted JSON results. The JSON I’m trying to parse has a shape like this: { "data": { "type": "video", "id": ...
Jadda asked 14/7, 2020 at 15:28

3

Solved

Within the app, we have two types of Stickers, String and Bitmap. Each sticker pack could contain both types. This is how I declare the models: // Mark: - Models protocol Sticker: Codable { } pu...
Snakebite asked 14/7, 2019 at 10:17

4

Solved

I had issue with JSON parsing in Swift 4.2. Here is the following code which shown runtime error. My Json data is as follow which i got from server. { code: 406, message: "Email Address alread...
Swarthy asked 27/10, 2018 at 10:2

3

I have the following data structure: { "type": "foo" "data": { /* foo object */ } } Here's my class for decoding it: final public class UntypedObject: Decodable { public var data: Data e...
Seaddon asked 29/10, 2017 at 10:24

4

Solved

Let's say I have the following decodable struct as an example illustrating what I'm trying to do: struct Object: Decodable { var id: String var name: String } and this JSON: [ { "id"...
Summarize asked 15/4, 2020 at 17:7

2

Solved

I'm refactoring some projects where I'd previously used third-party JSON parsers and I've encountered a goofy site that returns a boolean as a string. This is the relevant snippet from the JSON re...
Rosas asked 20/10, 2017 at 13:13

1

Solved

Is there a way to keep Swift's default implementation for a Decodable class with only Decodable objects but one exception? So for example if I have a struct/class like that: struct MyDecodable: De...
Bullnose asked 17/12, 2019 at 7:25

4

With API I'm working with, I have a case where 1 API Endpoint can return completely different responses, based on if the call was successful or not. In case of success, API Endpoint returns an Arra...
Leucippus asked 10/11, 2019 at 20:43

3

Solved

I know the basic concept of class and struct but which is more effective to create models for API to fetch data and tell me with pros and cons. Previously i don't use optional for models. Instead...
Cannon asked 31/10, 2019 at 6:38

© 2022 - 2025 — McMap. All rights reserved.