Hello, I’d like to have some hints about one thing:
In an array, bound to a tableview column, I have some numeric (float) values. These values are entered (put into the array) using interface buttons, labelled “0”, “1”, “2” and so on. There is also a “C” button to cancel an entry.
Later, I have some calculations to do with this array. If no result was entered, the array’s object cannot be 0. “No value” is certainly better represented by “nil”. but you are not allowed to insert a nil object into an array (nil means “end of array”.
A NSArray contains objects. That is, here, these object must be NSNumbers. So I can initialize my array by filling it with [NSNumber numberWithDouble:.] double what? I cannot put nil here!
A true NSArray does not (can not) contain “holes”. But mine has to, if for example, the third item never received a value. How can I:
implement an “undefined” value for my NSNumber?
make the “C” button erase a previously entered result?
use the @avg key for the column’s key (which hates when NSStrings are part of the calculation)
There must be a solution. In ASOC I used a trick: I did the attribution in the method called by every button, using its title, so:
if sender's title as string is "C" then
set item theRow of gResult to missing value -- the row was the selected line, gResult was a AS list.
else
set item theRow of gResult to sender's title as real
end if
What should I do here?
- choose a special value (say -1) to indicate an undefined value, then use a NSPredicate to filter my array?
- how could I turn the cell to “nothing” as the special value IS something?
I’m sure there is an elegant solution to this problem. But for now I just tear out what little hair I have left
Thank for help.