Re: putting structs in NSArray
Re: putting structs in NSArray
- Subject: Re: putting structs in NSArray
- From: Ben Dougall <email@hidden>
- Date: Tue, 26 Aug 2003 13:30:47 +0100
On Tuesday, August 26, 2003, at 12:42 pm, Alastair J.Houghton wrote:
On Tuesday, August 26, 2003, at 12:09 pm, Ben Dougall wrote:
this works fine for an NSRange:
NSRange r = NSMakeRange(50, 5);
NSValue *v = [NSValue valueWithBytes:&r objCType:@encode(NSRange)];
[array addObject: v]; // puts encoded struct into NSMutableArray
+valueWithBytes:objCType: appears to be deprecated in favour of
+value:objCType:, although some of the documentation seems to need
updating to say so.
but what about with another struct like say:
struct str s = {123456, '*', YES};
how can i now add s into an NSMutableArray?
Have you tried
NSValue *v = [NSValue value:&s objCType:@encode(struct str)];
i had tried
NSValue *v = [NSValue valueWithBytes:&s objCType:@encode(str)];
but that didn't work at all. your line gives much more promising
results than that, but from the build window:
main.m:36: warning: cannot find class (factory) method
main.m:36: warning: return type for `value:objCType:' defaults to id
and from the run window:
*** +[NSValue value:objCType:]: selector not recognized
See
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/
4objc_runtime_overview/chapter_4_section_6.html
for more information about @encode().
ok, i'll look into that now.
thanks very much.
ben.
_______________________________________________
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.