PDA

View Full Version : How to use Display Patterns in Cocoa Bindings?




gekko513
Oct 30, 2005, 11:03 PM
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
Oct 31, 2005, 05:18 AM
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 (http://developer.apple.com/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfCells.html) as a starting point.

gekko513
Oct 31, 2005, 05:48 AM
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
Oct 31, 2005, 09:27 AM
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:].