Re: value transformer for structs?
Re: value transformer for structs?
- Subject: Re: value transformer for structs?
- From: Derrick Bass <email@hidden>
- Date: Thu, 23 Mar 2006 12:21:06 -0600
On Mar 23, 2006, at 7:45 AM, Michael B Johnson wrote:
@implementation MYQTTimeRangeValueTransformer
+ (Class)transformedValueClass { return [NSString self]; }
+ (BOOL)allowsReverseTransformation { return NO; }
- (id)transformedValue:(id)value {
QTTimeRange* r = (QTTimeRange*)value;
return (value == nil) ? nil : QTStringFromTimeRange(*r);
}
@end
A QTTimeRange is not an object, so casting an id to a QTTimeRange* is
bad. What you need to do instead is use an NSValue internally. To get
the time range in and out, you can use valueWithQTTimeRange and
QTTimeRangeValue. E.g.
- (id)transformedValue:(id)value {
if (value == nil)
return nil;
QTTimeRange r = [value QTTimeRangeValue];
return QTStringFromTimeRange(r);
}
Of course, this also means that in whatever class you are binding to,
the ivar needs to be an NSValue instead of a QTTimeRange (or else the
accessor method needs to wrap the ivar in an NSValue).
(By the way, for your other example, an NSRect, bindings will
automatically do the wrapping and unwrapping for you. See <http://
developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/
Concepts/DataTypes.html#//apple_ref/doc/uid/20002171>)
I recently asked a similar question, but I never got a good answer
with regards to bindings; however, there was some good info if you
are using CoreData. The thread is here:
<http://lists.apple.com/archives/Cocoa-dev/2006/Mar/msg01135.html>
Derrick
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden