Adding an Entity

The next step is to factor (database-savvy developers would say normalize) ownTeam out of Game and into a new entity, Team. Click on Passer Rating.xcdatamodel, and (using the skills you picked up in Chapter 9, “An iOS Application: Model”) create the Team entity, with one attribute, teamName. teamName should be a string, indexed, not optional, and with an obviously bogus default name like UNASSIGNED_NAME. Add a relationship, games, tracing to many of the Game entity; deletion should cascade.

Game can lose the ourTeam attribute, and gain team, a to-one relationship to Team, nullifying on delete. Be sure to set up this relationship as the inverse of Team’s games. When you’re done, the diagram view of the data model should look like ...

Get Xcode 5 Start to Finish: iOS and OS X Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.