iOS Swift - 如何存储数组与Core Data? [英] iOS Swift - How to store array with Core Data?

查看:714
本文介绍了iOS Swift - 如何存储数组与Core Data?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS开发的新手,想知道应该指定哪种数据类型来存储多个字符串(数组)。该应用程序是与食物做,我需要存储多个成分作为一个属性。

I'm new to iOS development and was wanting to know which data type I should specify to store multiple strings (array). The app is to do with food and I need to store multiple ingredients as one attribute.

我想做成分作为实体,但我只是想让它容易起动器。
我已经阅读过关于transformable类型,但是人们似乎不推荐使用它来存储数组。

I was thinking of making ingredient as entity, but I just want to make it easy for a starter. I have read about transformable type but people don't seem to recommend using it to store arrays.

推荐答案

警告:提出意见的答案。

Warning: opinionated answer ahead.

你不是。

在数组中存储内容不会使您更容易。相反,它会使事情更难一小时。想象一下,你想显示包含选择的成分的所有食谱。这不会容易与你的数组hack,一个正确的模型,它只是一对夫妇的代码。

Storing things in an array does not make anything easier for you. On the contrary, it will make things much harder just an hour in. Imagine you want to show all Recipes that contain a selected Ingredient. That wouldn't be easy with your array hack, with a proper model it's only a couple line of code.

我建议与加入实体使用良好的旧关系。

I would recommend to use a good old relationship with a "Join-entity".

是的,这比骇人听闻的东西更复杂,几乎不起作用。但这是正确的方式。

Yes, this is more complicated than hacking something together that barely works. But it's the correct way.

这篇关于iOS Swift - 如何存储数组与Core Data?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆