How to use Display Patterns in Cocoa Bindings?

Discussion in 'Mac Programming' started by gekko513, Oct 30, 2005.

  1. gekko513 macrumors 603


    Oct 16, 2003
    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?
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    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.
  3. gekko513 thread starter macrumors 603


    Oct 16, 2003
    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.
  4. HiRez macrumors 603


    Jan 6, 2004
    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:].

Share This Page