[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: collections of primitive types
From: |
Chris B. Vetter |
Subject: |
Re: collections of primitive types |
Date: |
Fri, 28 Feb 2003 10:43:26 -0800 |
On Fri, 28 Feb 2003 10:26:24 -0800
Travis Griggs <tgriggs@keyww.com> wrote:
[...]
> NSArray looks fine for storing objects. But quite often I want an
> array of floats or ints. What's the general approach? Do I box up the
> primitive numbers in objects and use NSArray? Is there a FloatArray or
> IntArray thing? Write my own?
[...]
Use categories and methods ala
@implementation NSMutableArray (MyStuff)
- (void) addFloat: (float) value
{
[self addObject: [NSNumber numberWithFloat: value]];
return;
}
@end
@implementation NSArray (MyStuff)
- (float) floatAtIndex: (unsigned) index
{
id
value = [self objectAtIndex: index];
return ( [value respondsToSelector: @selector(floatValue)]
? [value floatValue]
: 0. ); // probably not the best return value...
}
@end
--
Chris