ios – methods to write enum with handbook decoding


I’ve a json response which is one thing like this:

"Particulars": {
        "Attachments": [],
        "place": {
          "vacation spot": {
            "kind": "worldwide",
            "Id": "superman",
            "locationType": "Metropolis",
            "Identify": "Kent"
          "bundle": 52.32,
          "description": "Dinner"

on this response all of the parameters in vacation spot are elective aside from kind, so i m dealing with this response like this:

public struct Vacation spot: Decodable, Equatable {
    public let Id: String?
    public let Identify: String?
    public let metropolis: String?
    public let locationType: String?
    public let pinCode: String?
    public let nation: String?
    public let state: String?
    public let foreign money: String?
    public let language: String?
    public let kind: Kind

as all of the parameters are elective and based mostly upto the sort i ll be getting solely few of those parameters in response.
like –

kind: "worldwide",
       nation: "US"
       id: "5",
       foreign money: "Greenback"

is there any method i can write this in an enum:

enum Vacation spot {
case worldwide(nation: String, id: String, foreign money: String)
case nationwide(state: String, language: String, pincode: String)

can anybody please reply how ought to i begin with this method.Thanks


Leave a Reply