Top "Codable" questions

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

Swift Codable expected to decode Dictionary<String, Any>but found a string/data instead

I have been working with the Codable protocol Here is my JSON file : { "Adress":[ ], "Object":[ { "next-date":"2017-10-30T11:00:00Z", "…

json swift swift4 codable
Swift's JSONDecoder with multiple date formats in a JSON string?

Swift's JSONDecoder offers a dateDecodingStrategy property, which allows us to define how to interpret incoming date strings in accordance with …

swift json-deserialization codable
Init an object conforming to Codable with a dictionary/array

Primarily my use case is to create an object using a dictionary: e.g. struct Person: Codable { let name: String } …

swift codable
Implementing a custom Decoder in Swift 4

I'd like to decode an XML document using the new Decodable protocol introduced in Swift 4, however, there doesn't seem to …

xml swift decoder codable swxmlhash
What is difference between optional and decodeIfPresent when using Decodable for JSON Parsing?

I am using Codable protocol from Swift 4 first time, I am not able to understand use of decodeIfPresent from Decodable. /// …

swift swift4 codable decodable
Using JSONEncoder to encode a variable with Codable as type

I managed to get both JSON and plist encoding and decoding working, but only by directly calling the encode/decode …

ios swift serialization protocols codable
How to encode Dictionary with JSONEncoder in Swift 4

I want to encode Dictionary to json with JSONEncoder. It seems like a Request, receive a dictionary as parameter and …

swift codable encodable jsonencoder
Encode nil value as null with JSONEncoder

I'm using Swift 4's JSONEncoder. I have a Codable struct with an optional property, and I'd like this property to …

ios json swift4 codable
Swift Codable with dynamic keys

I have JSON structure as: "periods": { "2018-06-07": [ { "firstName": "Test1", "lastName": "Test1" } ], "2018-06-06": [ { "firstName": "Test1", "lastName": "Test1" } ] } I tried …

json swift swift4 codable
How to use Codable protocol in objective c data model class?

I am working on mix and match iOS source code. I have implemented codable for swift data model class which …

objective-c swift codable