Calloc for Cocoa?
Calloc for Cocoa?
- Subject: Calloc for Cocoa?
- From: Tomas Zahradnicky <email@hidden>
- Date: Sun, 29 Jun 2003 21:11:26 -0700
Hello,
I was used to use calloc(number_of_items, sizeof(item)) to create
an array of items. Is there some similar thing in Cocoa? The approach
like this seems me quite complex:
NSArray* a = [NSMutableArray arrayWithCapacity:number_of_items];
MyItem* item = NULL;
for(i=0; i<number_of_items; i++)
[a addObject:[[MyItem alloc] init];
Of course I can add a class method to my item class that does this,
but I'm asking if there's not already a way how to do that.
i.e.
+(NSMutableArray*)arrayOfItems:(int)number
{
int i;
NSMutableArray* a = [NSMutableArray arrayWithCapacity:number];
for(i=0; i<number_of_items; i++)
[a addObject:[[[[self class] alloc] init] autorelease]];
return a;
}
-Tomas
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.