Re: initialize an NSArray with a list of objects
Re: initialize an NSArray with a list of objects
- Subject: Re: initialize an NSArray with a list of objects
- From: "Shawn Erickson" <email@hidden>
- Date: Tue, 16 May 2006 16:02:43 -0700
On 5/16/06, David Alter <email@hidden> wrote:
Is there a way to initialize an NSArray with a list of strings like I
can do in C
Example
the C way
char * myList[] = {"item1", "item2", "item3" }
I tried this, and it only picked up the first item
NSArray * myList = {@"item1", @"item2", @"item3" }
Thanks for the help
NSArray* myList = [NSArray arrayWithObjects:@"item1", @"item2", @"item3", nil];
(note you will need to retain myList if you want to have the array
last past the current autorelease pool)
Anyway the docs for NSArray outline these and related API
(initWithObjects:, etc.) and all that is available directly from Xcode
via a simple option double click of a class name (i.e. option-double
click "NSArray").
<file:///Developer/ADC Reference Library/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSArray.html#//apple_ref/occ/clm/NSArray/arrayWithObject:>
<file:///Developer/ADC Reference Library/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSArray.html#//apple_ref/occ/instm/NSArray/initWithObjects:>
- Shawn
_______________________________________________
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