• 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: putting structs in NSArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: putting structs in NSArray


  • Subject: Re: putting structs in NSArray
  • From: Dylan Adams <email@hidden>
  • Date: Tue, 26 Aug 2003 09:58:09 -0500

Ben Dougall wrote:
i just can't suss this one. trying to put a struct into an array:

struct str {
int x;
char y;
BOOL z;
};
struct str s = {123456, '*', YES};

NSMutableArray *a = [[NSMutableArray alloc] initWithCapacity:2];

NSValue *v = [NSValue value:&s objCType:@encode(struct str)];

The above line should be either

[NSValue valueWithBytes: &s objCType: @encode(struct str)];

or
[NSValue value: &s withObjCType: @encode(struct str)];

According to the documentation, they are equivalent.

[a addObject: v];

for the NSValue line i get:
main.m:34: warning: cannot find class (factory) method
main.m:34: warning: return type for `value:objCType:' defaults to id

seems as if @encode isn't getting the information it needs - it's not linking up with the str struct declaration or something? what am i doing wrong?

What made you think that? The error message is pretty clear. There's no class method on NSValue with the signature [value:objCType:]. There's nothing in that error message about @encode.

dylan
_______________________________________________
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.

References: 
 >Re: putting structs in NSArray (From: Ben Dougall <email@hidden>)

  • Prev by Date: Re: putting structs in NSArray
  • Next by Date: Re: My runs through Xcode but not in the Finder...
  • Previous by thread: Re: putting structs in NSArray
  • Next by thread: Re: putting structs in NSArray
  • Index(es):
    • Date
    • Thread