Database Reference
In-Depth Information
Spotlight/AppDelegate.m
if (!updatedObjects || ![updatedObjects count]) return YES;
NSNumber *_YES = [NSNumber numberWithBool:YES];
NSDictionary *attributesDictionary = [NSDictionary
dictionaryWithObject:_YES
forKey:NSFileExtensionHidden];
for (id object in updatedObjects) {
if (![object isKindOfClass:[PPRecipe class]]) continue ;
PPRecipe *recipe = object;
NSDictionary *metadata = [recipe metadata];
filePath = [recipe metadataFilename];
filePath = [path stringByAppendingPathComponent:filePath];
[metadata writeToFile:filePath atomically:YES];
[fileManager changeFileAttributes:attributesDictionary atPath:filePath];
}
return YES;
The last part of updating the metadata files is to process existing or new
recipes. As with the deleted objects earlier, we first check to see whether there
are any objects to update, and if there aren't, we are done. If there are new
or updated objects, we again loop through the NSSet looking for PPRecipe entities.
For each recipe we find, we request its metadata NSDictionary object from the
metadata method we created earlier. Using that NSDictionary along with the meta-
dataFilename method, we write the NSDictionary to disk. For one last bit of polish,
we update the attributes on the newly created (or updated) file and tell it to
hide its file extension. This gives us the cleanest appearance when viewed
inside the Finder.
Now that the -save: method has been written, we need to route all the -save:
calls that exist to call this method instead of calling -save: directly on the
NSManagedObjectContext . Currently, this requires modifying both the -(NSApplication-
TerminateReply)applicationShouldTerminate: method and the -(IBAction)saveAction: method.
In each case, we just need to change the following:
[[self managedObjectContext] save:&error];
to a message to the -save: method on the AppDelegate .
[self save:&error];
There is one last situation we need to handle. If we have existing users and
are adding the Spotlight integration after v1.0, we need some way to bring
our users up to speed. To do this, we add a check to the -(void)applicationDidFin-
ishLaunching: method. If the metadata directory does not exist, we must do a
full push of all the metadata in the persistent store.
 
 
 
Search WWH ::




Custom Search