• 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: Using NSValueTransformer with a double
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using NSValueTransformer with a double


  • Subject: Re: Using NSValueTransformer with a double
  • From: Paul Bruneau <email@hidden>
  • Date: Wed, 10 Oct 2007 11:51:06 -0400

On Oct 10, 2007, at 11:32 AM, Stephen F. Booth wrote:

I have an object with an instance variable of type NSTimeInterval
which as you know is actually just a double containing number of
seconds.

I would like to bind this ivar to an NSTextField on my interface
which works fine, except that it displays in seconds of course. I
want the user to experience this value in minutes.

So I look at NSValueTransformer which seems to be made exactly for
this type of thing.

I would recommend using NSFormatter in lieu of NSValueTransformer for this case, since you are just reformatting data for presentation to the user. It doesn't seem to me that you actually need to transform the value. In my experience the lines between NSValueTransformer and NSFormatter can become blurred.

I've written an NSFormatter subclass that does what you're after; see http://playosx.svn.sourceforge.net/viewvc/playosx/trunk/ Formatters/SecondsFormatter.m?view=markup for the source code.

OK I'll look at the docs for NSFormatter. Although Apple's example of NSValueTransformer where they show a Celcius to Farenheight conversion seems to me to be a nearly perfect analogy to my second to minute needs. So if my lines are blurry, I blame Apple :)


Thanks for the link to the source code too!


_______________________________________________

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


  • Prev by Date: Re: Cocoa-dev Digest, Vol 4, Issue 999
  • Next by Date: Re: Using NSValueTransformer with a double
  • Previous by thread: Re: Using NSValueTransformer with a double
  • Next by thread: Re: Using NSValueTransformer with a double
  • Index(es):
    • Date
    • Thread