• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: value transformer for structs?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: value transformer for structs?
      • From: "John C. Randolph" <email@hidden>
References: 
 >value transformer for structs? (From: Michael B Johnson <email@hidden>)
 >Re: value transformer for structs? (From: "John C. Randolph" <email@hidden>)
 >Re: value transformer for structs? (From: Michael B Johnson <email@hidden>)

  • Prev by Date: Re: Edit NSPopUpButtonCell like a text cell
  • Next by Date: Re: NSImages are killing my WindowServer
  • Previous by thread: Re: value transformer for structs?
  • Next by thread: Re: value transformer for structs?
  • Index(es):
    • Date
    • Thread