Top "Codable" questions

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

How to decode a property with type of JSON dictionary in Swift [45] decodable protocol

Let's say I have Customer data type which contains a metadata property that can contains any JSON dictionary in the …

json swift swift4 codable
Codable class does not conform to protocol Decodable

Why am I getting a "Type 'Bookmark' does not conform to protocol 'Decodable'" error message? class Bookmark: Codable { weak var …

swift swift4 codable decodable
How can I use Swift’s Codable to encode into a dictionary?

I have a struct that implements Swift 4’s Codable. Is there a simple built-in way to encode that struct into …

swift swift4 codable
Swift JSONDecode decoding arrays fails if single element decoding fails

While using Swift4 and Codable protocols I got the following problem - it looks like there is no way to …

arrays json swift swift4 codable
How do I use custom keys with Swift 4's Decodable protocol?

Swift 4 introduced support for native JSON encoding and decoding via the Decodable protocol. How do I use custom keys for …

json swift swift4 codable
With JSONDecoder in Swift 4, can missing keys use a default value instead of having to be optional properties?

Swift 4 added the new Codable protocol. When I use JSONDecoder it seems to require all the non-optional properties of my …

json swift swift4 codable
How to decode a nested JSON struct with Swift Decodable protocol?

Here is my JSON { "id": 1, "user": { "user_name": "Tester", "real_info": { "full_name":"Jon Doe" } }, "reviews_count": [ { "count": 4 } ] } Here is …

json swift swift4 codable
How to exclude properties from Swift 4's Codable

Swift 4's new Encodable/Decodable protocols make JSON (de)serialization quite pleasant. However, I have not yet found a way …

json swift codable
Encode/Decode Array of Types conforming to protocol with JSONEncoder

I'm trying to find the best way to Encode/Decode an array of structs conforming to a swift protocol using …

json swift encoding swift4 codable
Using Decodable in Swift 4 with Inheritance

Should the use of class inheritance break the Decodability of class. For example, the following code class Server : Codable { var …

swift swift4 codable