View Single Post
What is the best approach to add metadata to our OUIDocument subclass? I'm using the RTFDocument as an example and would like to add additional metadata to it such as keywords and PDF preview. Currently the RTFDocument example uses a flat NSData format rather than an NSFileWrapper, so the first step would be to address that. Something like this might work:

- (BOOL)readFromURL:(NSURL *)url error:(NSError **)outError;
    self.fileWrapper = [[NSFileWrapper alloc] initWithURL:url options:nil error:outError];
    NSString *rtfFilename = [url lastPathComponent];
    NSFileWrapper *rtfWrapper = [self.fileWrapper.fileWrappers objectForKey:rtfFilename];
    NSString *rtfString = [[NSString alloc] initWithData:[rtfWrapper regularFileContents] encoding:NSUTF8StringEncoding];
    NSAttributedString *attributedString = [OUIRTFReader parseRTFString:rtfString];
    _text = [attributedString copy];
    return YES;
Since there is a reference to the NSFileWrapper from this point, I could lazy load the metadata file and PDF preview similarly. Or perhaps I could lazy load the rtf data as well, just to keep the object graph as small as possible when dealing with a collection of documents.

Any overall thoughts on this? I guess I'm just looking for a code smell more than anything else to make sure I didn't miss anything crucial.