Re: Initialize NSArray with C array?
Re: Initialize NSArray with C array?
- Subject: Re: Initialize NSArray with C array?
- From: Scott Stevenson <email@hidden>
- Date: Wed, 22 Sep 2004 18:30:29 -0700
On Sep 22, 2004, at 9:55 AM, dkb wrote:
Is there a simple efficient way to initialize a NSArray with a C array
of doubles (converting them to NSNumbers in the process)? Perhaps
there is code for a category to NSArray that is floating around
already? I wish to do this to allow an F-Script script easy access to
the array..
You probably could have written such a function in the time it took to
write the email. :)
// assume sourceArray and SIZE exist
NSMutableArray * targetArray = [[NSMutableArray alloc]
initWithCapacity: SIZE];
int i;
NSNumber *number;
for (i = 0; i < SIZE; i++)
{
number = [NSNumber numberWithDouble: sourceArray[i]];
[targetArray addObject: number];
}
- Scott
--
Tree House Ideas
http://treehouseideas.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden