Top "Codable" questions

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

Swift Codable init

I would like to do some initialization logic after the Swift Coding/Encoding feature has finished decoding a JSON. struct …

json swift codable decodable
How to manually decode an an array in swift 4 Codable?

Here is my code. But I do not know what to set the value to. It has to be done …

swift codable
Swift String escaping when serializing to JSON using Codable

I'm trying to serialize my object as following: import Foundation struct User: Codable { let username: String let profileURL: String } let …

ios json swift macos codable
Type 'X' does not conform to protocol 'Encodable'

I am hoping here to get an understanding of this error and perhaps a broader understanding of encodable and decodable. …

ios swift xcode codable
Swift Decodable Optional Key

(This is a follow-up from this question: Using Decodable protocol with multiples keys.) I have the following Swift code: let …

ios json swift swift4 codable
Swift 4 Decodable - Dictionary with enum as key

My data structure has an enum as a key, I would expect the below to decode automatically. Is this a …

swift codable
Codable enum with default case in Swift 4

I have defined an enum as follows: enum Type: String, Codable { case text = "text" case image = "image" case document = "document" …

ios swift enums swift4 codable
Swift Codable decode empty json as nil or empty object

Here's my code: class LoginUserResponse : Codable { var result: String = "" var data: LoginUserResponseData? var mess: [String] = [] } public class LoginUserResponseData : Codable { var …

ios swift codable decodable
How to conform UIImage to Codable?

Swift 4 has Codable and it's awesome. But UIImage does not conform to it by default. How can we do that? …

uiimage swift4 codable
Swift Codable Decode Manually Optional Variable

I have the following code: import Foundation let jsonData = """ [ {"firstname": "Tom", "lastname": "Smith", "age": "28"}, {"firstname": "Bob", "lastname": "Smith"} ] """.data(using: .…

swift swift4 codable