Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Arrays in Cord data

I currently have a Swift 3 app that is using core data. What I would like to do is store an Array like list of strings. For example if a user clicks a button I want "yes" to be appended to the Array.

I know how to do this with an array and everything works fine, however what I need to do is store that array in core data. I did a little looking and it seems that this can be done with relationships. I was hoping that someone could point me in the direction of a good resource/ tutorial as how to actually implement this.

I have a list view each with an element. What I want is each element to have that "Array" of strings related to it. Any Help would be much appreciated

1 Answer

Figured it out! (Since it took me so long I'll share the answer for anyone who might find this later)

It is possible to store the data as an array by making the Core Data type 'Transformable' then in the Attributes section under Custom Class type Array<Any>. Now the core data attribute is essentially treated as an array, I would bet this works for dictionaries as well. Note: there is no relationship tables and this solution will store an Array in core data