Cannot invoke 'decode' with an argument list of type '(GenericDM.Type, from: String?)'

Cannot invoke 'decode' with an argument list of type '(GenericDM.Type, from: String?)'

I've been using app.quicktype.io to generate the code to decode JSON. I'm facing a problem now that I have not seen before.

I've been using app.quicktype.io to generate the code to decode JSON. I'm facing a problem now that I have not seen before.

First, I have this simple struct:

import Foundation

struct GenericDM: Codable { let status, statusMessage: String let result: [Result]

enum CodingKeys: String, CodingKey {
    case status
    case statusMessage = "status_message"
    case result
}

}

struct Result: Codable { let applicationID, applicationName, applicationType, suFirstName: String let suMiddleName, suLastName, suAge, suDob: String let suRace: String let suAddress: SuAddress let createdTime, updatedTime: Int

enum CodingKeys: String, CodingKey {
    case applicationID = "application_id"
    case applicationName = "application_name"
    case applicationType = "application_type"
    case suFirstName = "su_first_name"
    case suMiddleName = "su_middle_name"
    case suLastName = "su_last_name"
    case suAge = "su_age"
    case suDob = "su_dob"
    case suRace = "su_race"
    case suAddress = "su_address"
    case createdTime = "created_time"
    case updatedTime = "updated_time"
}

}

struct SuAddress: Codable { let addrLine1, addrLine2, stName, addrCity: String let addrState, addrCounty, addrPin: String

enum CodingKeys: String, CodingKey {
    case addrLine1 = "addr_line_1"
    case addrLine2 = "addr_line_2"
    case stName = "st_name"
    case addrCity = "addr_city"
    case addrState = "addr_state"
    case addrCounty = "addr_county"
    case addrPin = "addr_pin"
}

}

func newJSONDecoder() -> JSONDecoder { let decoder = JSONDecoder() if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) { decoder.dateDecodingStrategy = .iso8601 } return decoder }

func newJSONEncoder() -> JSONEncoder { let encoder = JSONEncoder() if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) { encoder.dateEncodingStrategy = .iso8601 } return encoder }

// MARK: - URLSession response handlers

extension URLSession { fileprivate func codableTask<T: Codable>(with url: URL, completionHandler: @escaping (T?, URLResponse?, Error?) -> Void) -> URLSessionDataTask { return self.dataTask(with: url) { data, response, error in guard let data = data, error == nil else { completionHandler(nil, response, error) return } completionHandler(try? newJSONDecoder().decode(T.self, from: data), response, nil) } }

func genericDMTask(with url: URL, completionHandler: @escaping (GenericDM?, URLResponse?, Error?) -&gt; Void) -&gt; URLSessionDataTask {
    return self.codableTask(with: url, completionHandler: completionHandler)
}

}

Then, I read a JSON file and try to decode the data from a different class:

    let bundle = Bundle.main
    let path = bundle.path(forResource: "MockGenericData", ofType: "json")
    let jsonData = try? String.init(contentsOf: URL.init(fileURLWithPath: path!))
    let genericDM = try? newGenericDMJSONDecoder().decode(GenericDM.self, from: jsonData)

I temporarily need to read from that mockup file before I can get it from the backend.

However, I'm getting Cannot invoke 'decode' with an argument list of type '(GenericDM.Type, from: String?)' and I don't understand why.

Anybody has any idea?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

What is JSON - JSON Parsing in Swift

What is JSON and how do you parse JSON in Swift? JSON stands for JavaScript Object Notation and it's a way to represent data in a standard way. Learn how to parse JSON in Swift using the Codable protocol. We take the response JSON data from a real API call and then parse it in Swift!

How to change the UITextfield text with data from JSON based on the value from UISlider in Swift 4?

Right now I have the UIText field hard coded and changing according to the value on the UISlider.

JSON Tutorial For Beginners | What is JSON | Learning JSON with JavaScript

JSON Tutorial For Beginners | What is JSON | Learning JSON with JavaScript