Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gekko513

macrumors 603
Original poster
Oct 16, 2003
6,301
1
Usually I'm able to find answers to my Cocoa questions either in the excellent Xcode documentation or by googling, but this problem has got me stumped.

How do I use the Display Patterns in Cocoa Bindings?
I've tried variations on these search terms: "cocoa bindings display pattern format string decimals".

I know that "%{value1}@ Mailboxes" will typically display something like "3 Mailboxes".

I would ideally like to find some good documentation on how to use the display patterns for advanced formatting of bound values.

If that doesn't exist, my current problem is how to use bindings to display a float value in an NSTextField as a decimal number with exactly two decimals as %.2f would do for printf.

Can someone help?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
I think you are looking at this the wrong way.

My understanding is that the display pattern provide a way to select a certain piece of data for display. They do not place any constraint on how that data is formatted.

Data formatting is done (as normal) by a formatter, in this case probably an instance of NSNumberFormatter.

Try this document as a starting point.
 

gekko513

macrumors 603
Original poster
Oct 16, 2003
6,301
1
Thanks, that was the solution I ended up with when I gave up searching.

I still wonder what exactly one can achieve with the display patterns and special operators on the binding values like @count and so forth.
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
I'd also like more information about this, the documentation from Apple (and anyone else) seems extremely thin on this point. As said, you can use a formatter object, or just bind to a method where you implement any custom formatting you need returning [NSString stringWithFormat:].
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.