views:

1734

answers:

3

I'm a new iPhone developer (of about 4 months or so) who is starting to look at Core Data.

In the "Beginning iPhone 3 Development" book by Dave Mark it mentions that the main difference between fetched properties and relationships is that fetched properties allow lazy loading. However, I have seen other resources and accepted answers on this site which suggest that relationships do allow lazy loading.

For example, if I have a Department object with a to-many relationship with Employee then I would not want a fetch on a given Department to load all the associated employees into memory.

I would be extremely grateful for an authoritative answer on this point, and on the other differences, as it has obvious implications on any design.

Also, I would be extremely grateful if someone could point me towards a reasonable Core Data resource that is a clear and beginner friendly guide (I have been a Java Developer previously but I am new to the iPhone-Way...

+5  A: 

Check out faulting in Core Data:

Using faults, if you retrieve a single Employee object from a persistent store its manager, department, and reports relationships are initially represented by faults. Although the fault is an instance of the Department class, it has not yet been realized—none of its persistent instance variables have yet been set.

If you send the Department object a message to get, say, its name, then the fault fires—and in this situation Core Data executes a fetch for you to retrieve all the object's attributes.

Alex Reynolds
so what does that mean now? A normal relationship can't point to a fault??
openfrog
I don't understand your question.
Alex Reynolds
+5  A: 

From the "Core Data Programming Guide", fetched properties represent "weak, one-way relationships". They simply allow you to define the value of a property with a fetch predicate rather than modeling it directly like a relationship.

One major difference is that fetched properties are not live or dynamic like direct relationships. You must explicitly keep fetched properties up-to-date by manually refreshing the object containing the fetched property when changes occur in your object graph that will affect the value of the fetched property.

Richard Stahl
ok so one has to manually call the fetching method on an playlist object to fetch all the songs; and when a song gets deleted, the playlist doesnt know about it until the "fetched property" called "songs" gets re-fetched again and returns less songs? does that make sense?
openfrog
A: 

I would highly recommend Core Data, by Marcus Zarra. I picked it up a few months ago, and while it is assumed you have some Objective-C experience, it's fairly accessible for beginners too.

Shawn Craver