Database Reference
In-Depth Information
You can accomplish this by turning on property loading while keeping
the -resultType as NSManagedObjectIDResultType . This is often referred to as
warming up the cache .
Loaded As a Fault
The next smallest amount of data we can retrieve is referred to as a fault-
ed NSManagedObject . What this means is the NSFetchRequest returns an NSArray of
NSManagedObject objects, but those objects contain only the NSManagedObjectID .
All the properties and relationships are empty or in a faulted state. As soon
as an attribute is accessed, all of the attributes on that object are loaded in .
Likewise, as soon as a relationship is accessed, all the NSManagedObject objects
on the other end of that relationship are loaded in as faults. Performing the
same query as earlier in this configuration returned the 3,417 records in
0.007 seconds. Faults will be discussed in greater depth in Section 4.4,
Faulting , on page 71 .
How to Retrieve Faulted NSManagedObject Objects
To disable the fetching of attributes as part of the NSFetchRequest , we need to
disable it prior to executing the fetch.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setIncludesPropertyValues:NO];
[fetchRequest setEntity:[NSEntityDescription entityForName:@ "Person"
inManagedObjectContext:[self managedObjectContext]]];
Although this seems like a great solution, it can be a bit of a trap. Because
this configuration returns empty skeletons, each object gets loaded from disk
individually. This is significantly slower than loading all the objects needed
at once. However, the time to load the objects is spread out and can be less
noticeable to the user. For raw speed, it is recommended that we load all the
data for the objects in one pass.
Loading Property Values
The next step up from faulted NSManagedObject objects is to prefetch their
property values. This will not retrieve the objects on the other sides of
relationships. Performing this query took 0.021 seconds for the 3,417 records
in the test repository.
How to Retrieve Only Property Values
Retrieving NSManagedObject objects with attributes populated is the default for
NSFetchRequest .
 
 
Search WWH ::




Custom Search