PDA

View Full Version : Beginners Question about Core Data fetchRequest




Glama
Aug 12, 2009, 09:08 PM
Hello!
I am trying to follow Apple's guide to Core Data. In one of their sample programs, they have this code:


NSManagedObjectModel *model = ...;

NSError *error;

NSDictionary *substitutionDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Fiona", @"FIRST_NAME", @"Verde", @"LAST_NAME", [NSDate dateWithTimeIntervalSinceNow:-31356000], @"DATE", nil];
NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"PublicationsForAuthorSinceDate" substitutionVariables:substitutionDictionary];

NSArray *results = [aManagedObjectContext executeFetchRequest:fetchRequest error:&error];


I dont even know if this code is reading from the store or writing to it. It seems like a "fetch" would be for reading, but data values are specified (hard coded) so it must be writing it. Am I correct?



doanelinde
Aug 14, 2009, 03:52 AM
No, fetch request is reading.

The fetch request specifies the entity you want.

This explains all:
http://developer.apple.com/iphone/library/documentation/DataManagement/Conceptual/iPhoneCoreData01/Articles/05_Fetching.html