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: "M. Uli Kusterer" <email@hidden>
- Date: Fri, 11 Jul 2003 17:42:43 +0200
At 10:09 Uhr -0500 11.07.2003, Dylan Adams wrote:
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.
Well, it gets the job done. But what he should really be doing, I
suppose, is declare an Objective-C class derived from NSObject and
have that contain a myStruct member variable. And then he would put
that in the NSMutableArray. That would be more OOP.
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
WARNING, typed up in Eudora (untested):
typedef struct myStruct myStruct; // Shorthand to save us one word.
// Class:
@interface MyStructClass : NSObject
{
myStruct data;
}
-(id) initWithStruct: (myStruct*)inStruct;
-(void) myStruct: (myStruct*)outStruct;
@end
// Implementation:
@implementation MyStructClass
-(id) initWithStruct: (myStruct*)inStruct
{
if( self = [super init] )
memmove( &data, inStruct, sizeof(myStruct) );
return self;
}
-(void) myStruct: (myStruct*)outStruct
{
memmove( outStruct, &data, sizeof(myStruct) );
}
@end
_______________________________________________
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.