codable Questions

10

Solved

Swift's JSONDecoder offers a dateDecodingStrategy property, which allows us to define how to interpret incoming date strings in accordance with a DateFormatter object. However, I am currently work...
Moslem asked 21/6, 2017 at 17:30

3

Solved

I'm going through some projects and removing JSON parsing frameworks, as it seems pretty simple to do with Swift 4. I've encountered this oddball JSON return where Ints and Dates are returned as St...
Rufinaruford asked 24/10, 2017 at 2:51

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

8

Solved

Swift 4 has Codable and it's awesome. But UIImage does not conform to it by default. How can we do that? I tried with singleValueContainer and unkeyedContainer extension UIImage: Codable { // 'r...
Failsafe asked 13/9, 2017 at 12:36

1

Solved

I'm trying to create a Codable struct with an [any Protocol] in Swift 5.7 struct Account: Codable { var id: String var name: String var wallets: [any Wallet] } protocol Wallet: Codable { var i...
Headway asked 26/7, 2022 at 12:47

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

6

Solved

With Xcode 10.2 and iOS 12.x we were able to extract Decimal from json string. With Xcode 11.1 and iOS 13.1 it is throwing exception Expected to decode Double but found a string/data instead. ...
Bigley asked 10/10, 2019 at 12:5

3

Solved

I have structs like struct RGBA: Codable { var r: UInt8 var g: UInt8 var b: UInt8 var a: UInt8 } I want save large amount of this structs (>1_000_000) Decode guard let history = try? JSO...
Bouilli asked 21/7, 2020 at 16:10

2

Solved

Recently i incorporated Codable in a project and to get a JSON object from a type conforming to Encodable i came up with this extension, extension Encodable { /// Converting object to postable J...
Church asked 22/10, 2018 at 5:26

5

Hy I am working on app that uses Realm and Alamofire. I am really happy in using these library in my iOS project. But then I have to post a List of models that contains multiple lists of models. ...
Shortchange asked 16/11, 2018 at 6:44

7

Should the use of class inheritance break the Decodability of class. For example, the following code class Server : Codable { var id : Int? } class Development : Server { var name : String? v...
Counterspy asked 14/6, 2017 at 20:13

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

4

Solved

In SwiftUI beta 5, Apple introduced the @Published annotation. This annotation is currently blocking this class from conforming to the Codable protocols. How can I conform to these protocols so I...
Picul asked 10/8, 2019 at 16:58

2

Solved

In testing how the new Codable interacts with NSCoding I have put together a playground test involving an NSCoding using Class that contains a Codable structure. To whit struct Unward: Codable { ...
Secessionist asked 7/6, 2018 at 16:57

7

Solved

Swift's Encodable/Decodable protocols, released with Swift 4, make JSON (de)serialization quite pleasant. However, I have not yet found a way to have fine-grained control over which properties shou...
Funky asked 20/6, 2017 at 14:16

16

Solved

Let's say I have Customer data type which contains a metadata property that can contains any JSON dictionary in the customer object struct Customer { let id: String let email: String let metada...
Eonism asked 17/6, 2017 at 10:3

5

Solved

Im facing an issue where I can't make the RealmOptional compatible with swift new Codable feature with json decoder. Cosider the following Realm object. class School: Object, Codable { @objc dy...
Kaon asked 12/7, 2018 at 9:31

16

Solved

While using Swift4 and Codable protocols I got the following problem - it looks like there is no way to allow JSONDecoder to skip elements in an array. For example, I have the following JSON: [ {...
Magog asked 21/9, 2017 at 13:16

3

Solved

I've seen answers on how to make an enum conform to Codable when all cases have an associated value, but I'm not clear on how to mix enums that have cases with and without associated values: ??? H...
Curable asked 25/8, 2019 at 7:13

6

Solved

I'm trying to adopt the Codable protocol for an object that must be instantiated from a JSON my web service returns in response to one of the API calls. One of the properties is of enumeration typ...
Ginkgo asked 6/11, 2018 at 3:14

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

2

Solved

Be default, Decodable protocol makes translation of JSON values to object values with no change. But sometimes you need to transform value during json decoding, for example, in JSON you get {id = "...
Morganite asked 1/8, 2017 at 5:57

5

Solved

I have structure like this: struct JSONModelSettings { let patientID : String let therapistID : String var isEnabled : Bool enum CodingKeys: String, CodingKey { case settings // The top leve...
Someplace asked 13/7, 2017 at 20:51

5

Solved

I am attempting to render a view from data returned from an API endpoint. My JSON looks (roughly) like this: { "sections": [ { "title": "Featured", "section_layout_type": "featured_panels", "...
Cornhusking asked 5/10, 2017 at 21:43

3

Primarily my use case is to create an object using a dictionary: e.g. struct Person: Codable { let name: String } let dictionary = ["name": "Bob"] let person = Person(from: dictionary) I woul...
Woodyard asked 20/9, 2017 at 16:28

© 2022 - 2025 — McMap. All rights reserved.