Signed incoherences with NSTableView indexes

  • It looks like that there are some incoherences in the way NSTableView
    deals with selection (from a signed/unsigned point of view).

    If you need to find the currently selected row, the recommended API is:

    - (int) selectedRow;

    If you need to find the currently selected rows, the recommended API is:

    - (NSIndexSet *) selectedRowIndexes;

    Considering that a NSIndexSet only deals with "unsigned
    int" (according to the header and documentation), this results in a
    strange situation where an index is either an int or an unsigned int.

    Wouldn't it be possible to only use "unsigned int" in the API
    definitions?
  • On Oct 17, 2006, at 6:56 AM, Stephane wrote:

    > It looks like that there are some incoherences in the way
    > NSTableView deals with selection (from a signed/unsigned point of
    > view).
    >
    > If you need to find the currently selected row, the recommended API
    > is:
    >
    > - (int) selectedRow;
    >
    > If you need to find the currently selected rows, the recommended
    > API is:
    >
    > - (NSIndexSet *) selectedRowIndexes;
    >
    > Considering that a NSIndexSet only deals with "unsigned
    > int" (according to the header and documentation), this results in a
    > strange situation where an index is either an int or an unsigned int.
    >
    > Wouldn't it be possible to only use "unsigned int" in the API
    > definitions?

    You would, of course, need some other way for selectedRow to indicate
    that there is no row selected if it returned an unsigned int.
    (selectedRow returns -1 if no row is selected).

    unsigned index;
    int r = [tv selectedRow];

    if (r != -1)
      index = (unsigned)r;

    Not exactly beautiful, I agree, but I guess we've got art and museums
    and stuff for that. :-/

    (please note ironic smiley)
  • On Oct 17, 2006, at 7:11 AM, R. Matthew Emerson wrote:

    >> It looks like that there are some incoherences in the way
    >> NSTableView deals with selection (from a signed/unsigned point of
    >> view).
    >
    > You would, of course, need some other way for selectedRow to
    > indicate that there is no row selected if it returned an unsigned
    > int.  (selectedRow returns -1 if no row is selected).

    Yeah, Matthew has got it, but this always bothered me. Why not
    declare selectedRow unsigned and use NSNotFound like other APIs? Just
    one of those things.

    ~Martin
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today