Database Reference
In-Depth Information
Spotlight/AppDelegate.m
NSError *error = nil;
NSString *path = [self metadataFolder:&error];
if (!path) {
NSLog(@ "%@:%s Error resolving cache path: %@" , [self class], _cmd, error);
return ;
}
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) return ;
NSManagedObjectContext *moc = [self managedObjectContext];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:[NSEntityDescription entityForName:@ "Recipe"
inManagedObjectContext:moc]];
NSSet *recipes = [NSSet setWithArray:[moc executeFetchRequest:request
error:&error]];
if (error) {
NSLog(@ "%@:%s Error: %@" , [self class], _cmd, error);
return ;
}
[self updateMetadataForObjects:recipes andDeletedObjects:nil error:&error];
if (error) {
NSLog(@ "%@:%s Error: %@" , [self class], _cmd, error);
return ;
}
Here we are looking for the metadata cache directory, and if it does not exist,
we fetch every recipe entity in the persistent store and pass the NSSet to our
metadata-building method. This also protects us from users who like to
periodically delete their cache directory. This method calls the -metadataFolder
method to determine where the metadata should be stored.
Spotlight/AppDelegate.m
- (NSString*)metadataFolder:(NSError**)error
{
NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
NSUserDomainMask, YES)
lastObject];
if (!path) {
NSMutableDictionary *errorDict = [NSMutableDictionary dictionary];
[errorDict setValue:NSLocalizedString(@ "Failed to locate caches directory" ,
@ "caches directory error description" )
forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:@ "pragprog" code:1000 userInfo:errorDict];
return nil;
}
path = [path stringByAppendingPathComponent:@ "Metadata" ];
path = [path stringByAppendingPathComponent:@ "GrokkingRecipes" ];
return path;
}
 
 
 
Search WWH ::




Custom Search