Re: How to add my custom structure to NSMutable Array??Pls help.
Re: How to add my custom structure to NSMutable Array??Pls help.
- Subject: Re: How to add my custom structure to NSMutable Array??Pls help.
- From: Glen Simmons <email@hidden>
- Date: Fri, 11 Jul 2003 10:37:12 -0500
On Friday, July 11, 2003, at 10:09 AM, Dylan Adams wrote:
Poornima wrote:
Hi,
I have a problem at hand,
I have a struct called myStruct, this struct needs to
be added to an NSMutableArray.
I need to keep adding myStruct to NSMutableArray "n"
times.
I am unable to achieve this:-((.
NSArray (and its subclasses, like NSMutableArray) only hold NSObjects.
It gives a lot of warning and when i try to debug, it
just stops at that the line where i get these
warnings.
I do not know about subclassing and other stuff as i
am quite new to mac.
Subclassing is not specific to Mac OS X developement, but part of a
methodology for structuring software systems: Object Orientated > Design.
Can anyone pls provide me with a easy working snippet
for the same.?
To put structs into an NSArray, you need to wrap them with an NSValue
object. Given p, a pointer to a myStruct, and array, an instance of
NSMutableArray:
[array addObject: [NSValue valueWithPointer: p]];
should be what you want.
You could always keep things simpler and just use a C array:
myStruct *structArray[10];
structArray[0] = newStruct;
HTH,
Glen
_______________________________________________
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.