Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: alloc ... initWith ... malloc and NSObject




On Jun 11, 2005, at 9:52 PM, email@hidden wrote:

I have a class called MyScene that shall hold an array of objects
called MyPolygon. MyPolygon is derived from NSObject and have
the following function:

- (id)initWithVertexCount:(int)vertexCount;

I also need to create an array of MyPolygon objects in MyScene
at the following location:
- (id)initWithPolygonCount:(int)polygonCount;

Now the problem is how do I create an array of MyPolygon
objects without using NSMutableArray but perhaps using malloc
and yet still manage to call the initWithVertexCount method?

So you mean a C array? Then you would do it just like you do in C:

MyPolygon **polygons = malloc(polygonCount * sizeof(MyPolygon *));
int i;

for (i = 0; i < polygonCount; i++) {
    polygons[i] = [[MyPolygon alloc] initWithVertexCount:vertexCount];
}

-Prachi
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >alloc ... initWith ... malloc and NSObject (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.