Swift-将字典保存到核心数据

发布于 2025-01-27 16:04:31 字数 510 浏览 3 评论 0原文

作为特定对象的API响应的一部分,我们会收到以下内容:

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

但是,itemcaptions可以包含一个不确定的数字和值范围,每个数字[string:string:string] > 。

因此,在我的数据模型中,我将其设置为如下:

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

这可以正常工作,除了我需要能够将此模型的实例存储在核心数据中,但我不确定如何处理。我已经有一个item实体,但是如何设置一个关系以表示键可以是任何键的字典项目?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文