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

Core data question

Hey all,

So i am just starting out with core data and wanted to clear something up before i moved further. If i wanted a question and and answer to stay together, (similar to wanting a user name and password to stay together) would i create a Question entity, and then an answer attribute ? Or would i want to create a QApair entity and an attribute each for question and answer?

Also, within my model would i still need to use tuples or a dictionary to keep the question and answer together, or can i just make a questions array and an answers array and then let core data handle keeping them linked?

thanks in advance for the help

1 Answer

Gabe Nadel
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Gabe Nadel
Treehouse Guest Teacher

Whether or not you use CoreData (which you should, b/c it's great practice) you want to create the notion of a "question" object. And yes, you'd create an entity in CoreData for that. This is object-orientation, so the "question" is the unit that is playing the key role here.

However, the word "question" can mean a few things. To clear up that ambiguity, I'd suggest that you name your entity "Question." but, the attributes of the entity could be "questionPrompt" and "answer". Of course, a great added bonus of this model is that you can later add another attribute for "difficulty", or "answerFeedback" or "pointValue" and that's MUCH cleaner when it's based around the entity, rather than a growing list of interconnect arrays. (Yes, arrays can do the job, but it's not nearly as clean or extensible.)

Gabe,

Thanks for the reply. So that makes sense. I am definitely going to stick with using Core data as i do need the practice, so i do have more to learn, but let me see if i am understanding correctly. Being i am working on a flashcard project, both the question and the answer would be user inputted. So would i want to create the Question entity with both a question and answer attribute? This is where i get stuck, how will i keep the related question and answer together in Core data? and being i am using Core data, do i need to use an array at all to hold all the user inputted question and answers?

Forgive me if i will answer my own questions with more research, but i just want to get an idea from an expert so i can move forward with the development of the project. (i learn as i go more easily than reading)