• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Initialize NSArray with C array?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Initialize NSArray with C array?
      • From: Allan Odgaard <email@hidden>
References: 
 >Initialize NSArray with C array? (From: dkb <email@hidden>)

  • Prev by Date: Error
  • Next by Date: menu & multiple windows
  • Previous by thread: Initialize NSArray with C array?
  • Next by thread: Re: Initialize NSArray with C array?
  • Index(es):
    • Date
    • Thread