我正在使用Swift,我需要你的帮助。
当我无法设置属性时,如何将相关属性/参数保存到CoreData。
在我的应用程序中,用户可以创建无限数量的文本字段,我需要将其保存到CoreData。我怎样才能做到这一点?我对CoreData有点新意,我想要一些帮助。有小费吗?我知道我需要设置属性但是如果用户可以创建无限数量的文本字段并且可以保存我如何使用CoreData执行此操作?谢谢你的帮助:)
答案 0 :(得分:0)
通常,这是通过为您的字段创建模型来完成的......然后,您可以为相关对象提供ToMany关系。
Fruit
- name (string)
- avg_weight (number)
- characteristics (characteristic with to many relation)
Characteristic
- name (string)
- value (string)
然后,您可以使用类别在Fruit上提供getter / setter ...
Fruit (CharacteristicAdditions)
- generalShape (string) // lookup characteristics where name == 'general_shape' and return value
这个值就是你可以使用谓词来查找特征来做一些事情,比如查找所有的水果,其中包括' general_shape'是圆的'。
总是存在编码的次要选择,如JSON或任何其他序列化格式......因此:
Fruit
- name (string)
- avg_weight (number)
- characteristics (string, json object, name as key, value as value)
您仍然需要一个类别来访问“清洁”中的编码特征字段。方式。