1

How do we model relationships with attributes in core data. I know I am thinking in terms of Databases. But I am very new to core data. So please help me get it.

I need to store students information, books information and the relationship between them, which is the number of minutes a student has read a particular book on a particular day (date). I am having no clue on how to do this.

Can anyone please help me figure it out...

user1118321
  • 25,567
  • 4
  • 55
  • 86
Aragorn
  • 34
  • 5

3 Answers3

0

Excellent tutorial on core data basics by Ray Wenderlich, explains creating entities and modeling relationships. http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started

rbs
  • 112
  • 3
  • This page helped me get a basic idea.Thank you very much. But I am looking for a complex example. – Aragorn Apr 30 '14 at 21:15
0

These two good books helped me...

from The Pragmatic Bookshelf – "Core Data, 2nd Edition, Data Storage and Management for iOS, OS X, and iCloud" (Jan 2013) by Marcus S. Zarra.

from Apress publishers – "Pro iOS Persistence Using Core Data", by Michael Privat and Robert Warner (still in alpha).

Beyond that, I wrote this answer recently about a similar question... have a look and replace their Player with your Student, and their Game with your Book.

In my mind you need to focus on these tasks;

  • Prepare your data model (on paper, etc), then translate that into a Core Data Model .xcdatamodeld file, using attributes to manage entity values, and relationships to manage the relationships to other entities.
  • Under the Xcode menu Editor, Create NSManagedObject Subclasses... for each entity. (Note this step is not necessary, however greatly simplifies the process of accessing your entities, attributes and relationships),
  • Prepare and initialise your "Core Data Stack" in your code. There are different methods for achieving the same outcome here. Start by using the default template provided by Apple. To do this, check the Use Core Data checkbox when you create a new project.

Hope this helps.

Community
  • 1
  • 1
andrewbuilder
  • 3,629
  • 2
  • 24
  • 46
0

And I figured it out. I split the many-to-many relation into 2 one-to-many relations with a third entity (say readingInfo) and gave the attributes of the relationship like date and number of minutes read ,to this entity.

This might help others trying to do the same thing.

Aragorn
  • 34
  • 5