5. Attributes
NSNumber
NSString Transformable
BOOL You put in code to
transform the
NSDate
object or value into
NSData a compatible type.
Transformable
6. Relationships
Properties that reference other objects
Can be to-one or to-many (NSSet - unordered)
Can (and should) have inverses, which are worked
out by Core Data when you set the other property
Delete rule ensures propagation
7. Relationships
DTAlbum
Attributes
DTArtist name
DTGenre Attributes discCount
Attributes name trackCount
name Relationships Relationships
Relationships albums artist
artists genres composers
songs songs songs
8. Core Data Stack
NSManagedObjectContext
NSPersistentStoreCoordinator NSPersistentStore
NSManagedObjectModel
10. Create and Save Objects
NSManagedObjectContext
DTArtist
DTSong
NSPersistentStoreCoordinator NSPersistentStore
NSManagedObjectModel
11. Fetching Objects
All songs by “La Roux” sorted by title.
Entity DTSong
Predicate @“artist.name == %@”, @“La Roux”
Sorting @“title”
12. Fetching Objects
Fetch all playlists which contain more than an hour of music.
Entity DTPlaylist
Predicate @“@sum.songs.duration > 3600”
Sorting @“name”
15. Performance: Faults
Faults are placeholders for related objects, which
mean you don’t use memory on unwanted objects.
DTSong
DTSong
DTArtist DTSong
DTSong
DTSong
16. Performance: Batching
DTArtist
DTArtist
Batching allows
you to bring only a DTArtist
subset of objects DTArtist
into memory.
DTArtist
DTArtist