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...
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...
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...
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.
...
3
Solved
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...
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. ...
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...
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...
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 {
...
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...
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...
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:
[
{...
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...
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...
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 = "...
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...
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",
"...
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...
© 2022 - 2025 — McMap. All rights reserved.