Custom Value Transformer for PDFDocument data
Custom Value Transformer for PDFDocument data
- Subject: Custom Value Transformer for PDFDocument data
- From: Kevin Ross <email@hidden>
- Date: Sat, 10 May 2008 15:19:01 -0700
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 (email@hidden)
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:
This email sent to email@hidden