Issue with building data model in swift for Oxford dictionary API

122 views Asked by At

I'm trying to implement data model using Oxford Dictionary API, I've created the below data model in Swift based on the documentation, but Xcode is throwing the below error that does not show exactly where the problem is, thus paralyzing me, but I believe it shall work fine, if I manually go through the sample data and decode in brute force manner. I can't understand where the issue is, wondering if someone can help.

error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=EXC_I386_GPFLT). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

//: A UIKit based Playground for presenting user interface
  
import UIKit
import PlaygroundSupport



let json =
    """
{
  "id": "excruciating",
  "metadata": {
    "operation": "retrieve",
    "provider": "Oxford University Press",
    "schema": "RetrieveEntry"
  },
  "results": [
    {
      "id": "excruciating",
      "language": "en-us",
      "lexicalEntries": [
        {
          "entries": [
            {
              "pronunciations": [
                {
                  "dialects": [
                    "American English"
                  ],
                  "phoneticNotation": "respell",
                  "phoneticSpelling": "ikˈskro͞oSHēˌādiNG"
                },
                {
                  "audioFile": "https://audio.oxforddictionaries.com/en/mp3/excruciating_us_1.mp3",
                  "dialects": [
                    "American English"
                  ],
                  "phoneticNotation": "IPA",
                  "phoneticSpelling": "ɪkˈskruʃiˌeɪdɪŋ"
                }
              ],
              "senses": [
                {
                  "definitions": [
                    "intensely painful"
                  ],
                  "examples": [
                    {
                      "text": "excruciating back pain"
                    }
                  ],
                  "id": "m_en_gbus0340190.005",
                  "shortDefinitions": [
                    "intensely painful"
                  ],
                  "subsenses": [
                    {
                      "definitions": [
                        "mentally agonizing; very embarrassing, awkward, or tedious"
                      ],
                      "examples": [
                        {
                          "text": "excruciating boredom"
                        }
                      ],
                      "id": "m_en_gbus0340190.008",
                      "shortDefinitions": [
                        "very embarrassing or tedious"
                      ]
                    }
                  ],
                  "synonyms": [
                    {
                      "language": "en",
                      "text": "agonizing"
                    },
                    {
                      "language": "en",
                      "text": "extremely painful"
                    },
                    {
                      "language": "en",
                      "text": "severe"
                    },
                    {
                      "language": "en",
                      "text": "acute"
                    },
                    {
                      "language": "en",
                      "text": "intense"
                    },
                    {
                      "language": "en",
                      "text": "extreme"
                    },
                    {
                      "language": "en",
                      "text": "savage"
                    },
                    {
                      "language": "en",
                      "text": "violent"
                    },
                    {
                      "language": "en",
                      "text": "racking"
                    },
                    {
                      "language": "en",
                      "text": "searing"
                    },
                    {
                      "language": "en",
                      "text": "piercing"
                    },
                    {
                      "language": "en",
                      "text": "stabbing"
                    },
                    {
                      "language": "en",
                      "text": "raging"
                    },
                    {
                      "language": "en",
                      "text": "harrowing"
                    },
                    {
                      "language": "en",
                      "text": "tormenting"
                    },
                    {
                      "language": "en",
                      "text": "grievous"
                    }
                  ],
                  "thesaurusLinks": [
                    {
                      "entry_id": "excruciating",
                      "sense_id": "t_en_gb0005204.001"
                    }
                  ]
                }
              ]
            }
          ],
          "language": "en-us",
          "lexicalCategory": {
            "id": "adjective",
            "text": "Adjective"
          },
          "text": "excruciating"
        }
      ],
      "type": "headword",
      "word": "excruciating"
    }
  ],
  "word": "excruciating"
}
""".data(using: .utf8)

struct RetrieveEntry: Codable {
    let id : String?
    let metadata : Metadata?
    let results : [HeadwordEntry]?
    struct Metadata : Codable {
        let operation : String?
        let provider : String?
        let schema : String?
    }
    let word : String?
}

struct HeadwordEntry : Codable {
    let id : String
    let language : String
    let lexicalEntries : [LexicalEntry]
    let pronunciations : [Inline_Model_1]?
    let type : String?
    let word : String?
}


struct LexicalEntry : Codable {
    let compounds : [Inline_Model_2]?
    let derivativeOf : [Inline_Model_2]?
    let derivatives : [Inline_Model_2]?
    let entries : [Entry]?
    let grammaticalFeatures : Inline_Model_3?
    let language  : String
    let lexicalCategory : Inline_Model_7
    let notes : [Inline_Model_4]?
    let phrasalVerbs : [Inline_Model_2]?
    let phrases : [Inline_Model_2]?
    let pronunciations :  [Inline_Model_1]?
    let root : String?
    let text : String
    let variantForms : [Inline_Model_5]?
}

struct Entry : Codable {
    let crossReferenceMarkers : [String]?
    let crossReferences : [Inline_Model_3]?
    let etymologies : [String]?
    let grammaticalFeatures : [Inline_Model_3]?
    let homographNumber : String?
    let inflections : [InflectedForm]?
    let notes : [Inline_Model_4]?
    let pronunciations : [Inline_Model_1]?
    let senses : [Sense]?
    let variantForms : [Inline_Model_5]?
}

struct Inline_Model_1 : Codable {
    let audioFile : String?
    let dialects : [String]?
    let phoneticNotation : String?
    let phoneticSpelling : String?
    let regions : [Inline_Model_7]?
    let registers : [Inline_Model_7]?
}
struct Inline_Model_2 : Codable {
    let domains : [Inline_Model_7]?
    let id : String
    let language : String?
    let regions : [Inline_Model_7]?
    let registers : [Inline_Model_7]?
    let text : String
}

struct InflectedForm  : Codable {
    let domains : [Inline_Model_7]?
    let grammaticalFeatures : [Inline_Model_3]?
    let inflectedForm : String
    let lexicalCategory : [Inline_Model_7]?
    let pronunciations : [Inline_Model_1]?
    let regions : [Inline_Model_7]?
    let registers : [Inline_Model_7]?
}
struct Sense : Codable {
    let antonyms : [Inline_Model_10]?
    let constructions : [Inline_model_2]?
    let crossReferenceMarkers: [String]?
    let crossReferences : [Inline_Model_3]?
    let definitions : [String]?
    let domainClasses: [Inline_Model_7]?
    let domains : [Inline_Model_7]?
    let etymologies: [String]?
    let examples : [Inline_Model_12]?
    let id : String?
    let inflections : [InflectedForm]?
    let notes : [Inline_Model_4]?
    let pronunciations : [Inline_Model_1]?
    let regions : [Inline_Model_7]?
    let registers : [Inline_Model_7]?
    let semanticClasses : [Inline_Model_7]?
    let shortDefinitions : [String]?
    let subsenses : [Sense]?
    let synonyms : [Inline_Model_10]?
    let thesaurusLinks : [ThesaurusLink]?
    let variantForms : [Inline_Model_5]?
    struct ThesaurusLink : Codable {
        let entry_id : String
        let sense_id : String
    }
}

struct Inline_Model_5 : Codable {
    let domains : [Inline_Model_7]?
    let notes : [Inline_Model_4]?
    let pronunciations : [Inline_Model_1]?
    let regions : [Inline_Model_7]?
    let registers : [Inline_Model_7]?
    let text : String
}

struct Inline_model_2 : Codable {
    let domains : [Inline_Model_7]?
    let examples : [String]?
    let notes : [Inline_Model_4]?
    let regions : [Inline_Model_7]?
    let registers : [Inline_Model_7]?
    let text : String
}

struct Inline_Model_3 : Codable {
    let id : String
    let text : String
    let type :  String
}
struct Inline_Model_4 : Codable {
    let id : String?
    let text : String
    let type :  String
}

struct Inline_Model_7 : Codable {
    let id : String
    let text : String
}

struct Inline_Model_10 : Codable {
    let domains : [Inline_Model_7]?
    let id : String?
    let language : String?
    let regions : [Inline_Model_7]?
    let registers : [Inline_Model_7]?
    let text : String
}

struct Inline_Model_12 : Codable {
    let definitions : [String]?
    let domains : [Inline_Model_7]?
    let notes : [Inline_Model_4]?
    let regions : [Inline_Model_7]?
    let registers : [Inline_Model_7]?
    let senseIds : [String]?
    let text : String
}


var decoder = JSONDecoder()

var sample = try! decoder.decode(RetrieveEntry.self, from: json!)


Thanks a lot for spending time to go through this

0

There are 0 answers