iOS Swift - How to store array with Core Data?

Warning: opinionated answer ahead.

You don't.

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".

basic Recipe data model

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


What you was thinking of is exactly what you should do. Core Data is made to store values in array like structure. You should create entity Ingredients and connect your Food entity (or whatever you would like to call it) with relationship with Ingredients entity.