NSFormatter or NSValueTransformer?

Discussion in 'Mac Programming' started by BadWolf13, Sep 25, 2011.

  1. BadWolf13 macrumors 6502

    Joined:
    Dec 17, 2009
    #1
    Hello everyone, got a question about something that I'm not sure which way to go on.

    I've got a database that's going to be displayed in a table view. Now one of the items is an integer, but I don't want the table view to display the number, I want it to display a string that corresponds to the integer value. Now I'm not sure which way to go about this. Should I use a custom NSFormatter, or an NSValueTransformer? Or is there a completely different way I should go about this?

    PS, the reason I went about using an integer instead of just a string is that the user is only be able to select from a predefined list of values that are presented in a pop-up button in another window.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Assuming you're using bindings, I'd just use NSValueTransformer. Bind your object or attribute to the column, then apply the transformer that generates the string.

    NSFormatter is more used when you have input that needs to be restricted to a certain format.
     
  3. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009

Share This Page