views:

42

answers:

1

What's the point of a fetched property? Does someone have a good example what this is good for?

+2  A: 

Some of the uses for fetched properties:

  1. Ordered relationships. The Core Data to-many relationship models a (unordered) set. You can provide the appearance of an ordered relationship using a fetched property with a sort descriptor (assuming there's a natural ordering to the elements).
  2. Cross-store relationships. Relationships in Core Data cannot span persistent stores. You can simulate such relationships using fetched properties, for example storing the objectIDs of the destination in a transformable property and fetching the elements of that collection of objectIDs. Obviously true cross-store relationships are problematic because there's no way to guarantee the presence of an other store at access time.
  3. Filtered relationships. Although fetched properties are not "live' (like iTunes' smart playlists), they can be used to easily filter members of one or more relationships according to attributes (persistent or transient) of any object in the connected object graph.
Barry Wark
So basically, I could also simply use normal properties and relationships (no fetched) and then make fancy fetch request methods somewhere else in my code, to approach the same thing?
dontWatchMyProfile
Well, you can't use normal relationships for cross-store links. Otherwise, yes, except that for SQLite persistent stores, fetched properties can execute in the database, giving benefits in both speed and memory usage.
Barry Wark