0

As part of an API response for a particular object we receive the following:

"itemNotes" : {
        "disclaimer" : "some text here"
      },

However, itemCaptions can contain an indeterminate number and range of values, each with type [String: String].

So within my data model I am setting this up as follows:

struct Item: Codable, Equatable, Identifiable, Hashable {
    ...
    let itemNotes: [String: String]?
    ...
}

This works fine, except that I need to be able to store instances of this model in core data but I am unsure how to go about this. I already have an Item entity but how can I set up a relationship to represent a dictionary item whose key could be anything?

DevB1
  • 1,235
  • 3
  • 17
  • 43
  • This can be achieved by Transformable type in Core Data. https://developer.apple.com/documentation/coredata/handling_different_data_types_in_core_data – Kush Bhavsar May 10 '22 at 17:03
  • Does this answer your question? [Best practice? - Array/Dictionary as a Core Data Entity Attribute](https://stackoverflow.com/questions/1562676/best-practice-array-dictionary-as-a-core-data-entity-attribute) – Kush Bhavsar May 10 '22 at 17:04
  • One option is to store the original json as a string attribute another one is to create an entity with two string attributes, key and value – Joakim Danielson May 10 '22 at 17:06

0 Answers0