Hello, I'm thinking of implementing a Custom Value Transformer to add PDFDocument support to a MangedObject. I just want to see if I'm on the right track or not. The code below works, I'm just not sure if this is the proper way to do this. Thanks for your feedback.

@implementation PDFDataTransformer

+ (Class)transformedValueClass { return [NSData class]; }

+ (BOOL)allowsReverseTransformation { return YES; }


- (id)transformedValue:(id)value
{
   NSData *pdfDocAsData = nil;
        
   if (value == nil) return nil;
        
   // Attempt to get a reasonable value from the
   // value object.
   if ([value respondsToSelector: @selector(dataRepresentation)]) {
       pdfDocAsData = [value dataRepresentation];
   } else {
       [NSException raise: NSInternalInconsistencyException
format: @"Value (%@) does not respond to - dataRepresentation.",
                 [value class]];
   }
        
   return [pdfDocAsData autorelease];
}

- (id)reverseTransformedValue:(id)value
{
   PDFDocument *pdfDoc = nil;
        pdfDoc = [[PDFDocument alloc] initWithData:value];
        return [pdfDoc autorelease];
}

----------------------------------------------------------------------------------------------------------

My other approach was to add an pdfDoc ivar & property and add this code:

- (void) init  { pdfDoc = [[PDFDocument alloc] init]; }
- (void) dealloc { [pdfDoc release]; }

and change - (id)reverseTransformedValue:(id)value   to:
- (id)reverseTransformedValue:(id)value
{
        [pdfDoc initWithData:value];
        return pdfDoc;
}

Any suggestions?

Thank you all again for you expertise.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to