Database Reference
In-Depth Information
The other gotcha with Spotlight is that the importer needs to be as fast as
possible. What might be acceptable for processing one file or ten files is not
going to fly when Spotlight has to chug through thousands of files. Since the
same importer that we are writing for use inside our application could
potentially be used in a server situation, it needs to be as fast as we can make
it. So, we're going to cheat a bit. Instead of looking up the metadata in our
Core Data repository upon request from Spotlight, we'll instead store the
metadata in the files we are creating for Spotlight. That way, our importer
has to touch the metadata files only and does not need to initialize the entire
Core Data “stack” (that is, NSManagedObjectContext , NSPersistentStoreCoordinator , and
NSManagedObjectModel ).
Creating the Metadata Files
We first need to produce and update the metadata files on the fly. To keep
them as simple as possible, we just use plist files, as opposed to a binary
representation or some other format. Since NSDictionary understands plist files,
it reduces the amount of overhead needed for loading and saving the files.
To begin, let's create our first NSManagedObject subclass. This subclass handles
producing the NSDictionary that will contain all the metadata. Since we are
creating a subclass, we might as well implement some of the properties we
will be using to reduce the code complexity and make it easier to maintain.
Therefore, our header file looks as follows:
Spotlight/PPRecipe.h
#import <Cocoa/Cocoa.h>
extern NSString *kPPImagePath;
extern NSString *kPPObjectID;
extern NSString *kPPServes;
@interface PPRecipe : NSManagedObject {
}
@property (assign) NSString *desc;
@property (assign) NSString *name;
@property (assign) NSString *type;
@property (assign) NSManagedObject *author;
@property (assign) NSDate *lastUsed;
- (NSDictionary*)metadata;
- (NSString*)metadataFilename;
@end
 
 
 
Search WWH ::




Custom Search