Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Created February 26, 2013 10:12
Show Gist options
  • Select an option

  • Save lamprosg/5037445 to your computer and use it in GitHub Desktop.

Select an option

Save lamprosg/5037445 to your computer and use it in GitHub Desktop.
(iOS) - Core Data [incomplete]
An entity is made up of properties. There are three types of properties:
Attributes: An attribute serves the same function in a Core Data entity as an instance variable does in an Objective-C class.
They both hold the data.
Relationships: As the name implies, a relationship defines the relationship between entities.
For example, to create a Person entity, you might start by defining a few attributes such as hairColor, eyeColor, height
and weight. You might define address attributes, such as state and ZIP code, or you might embed them in a separate HomeAddress
entity.
Using the latter approach, you would then create a relationship between a Person and a HomeAddress.
Relationships can be to-one and to-many.
The relationship from Person to HomeAddress is probably to-one, since most people have only a single home address.
The relationship from HomeAddress to Person might be to-many, since there may be more than one Person living at that HomeAddress
Fetched properties: A fetched property is an alternative to a relationship.
Fetched properties allow you to create a query that is evaluated at fetch time to see which objects belong to the relationship.
To extend our earlier example, a Person object could have a fetched property called Neighbors that finds all HomeAddress
objects in the data store that have the same ZIP code as the Person’s own HomeAddress. Due to the nature of how fetched
properties are constructed and used, they are always one-way relationships.
Fetched properties are also the only kind of relationship that lets you traverse multiple data stores.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment