Swift-将字典保存到核心数据
作为特定对象的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论