• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to add my custom structure to NSMutable Array??Pls help.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: How to add my custom structure to NSMutable Array??Pls help.
      • From: Jeff Harrell <email@hidden>
References: 
 >How to add my custom structure to NSMutable Array??Pls help. (From: Poornima Ranganath <email@hidden>)
 >Re: How to add my custom structure to NSMutable Array??Pls help. (From: Dylan Adams <email@hidden>)

  • Prev by Date: Re: How to add my custom structure to NSMutable Array??Pls help.
  • Next by Date: Install two Mac OSX on one computer
  • Previous by thread: Re: How to add my custom structure to NSMutable Array??Pls help.
  • Next by thread: Re: How to add my custom structure to NSMutable Array??Pls help.
  • Index(es):
    • Date
    • Thread