Re: Casting from NSArray to a custom class
Re: Casting from NSArray to a custom class
- Subject: Re: Casting from NSArray to a custom class
- From: "newdev@yahoo" <email@hidden>
- Date: Wed, 16 Feb 2005 01:37:06 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hi all,
As for details of what I want to do -
I have got an NSArray* that should contain some data; a list(array) of
struct mystruct
{
unsigned long varA;
unsigned long varB;
}
objects.
By accessing the NSArray sequentially I want to extract and access its elements just like the C structure described above. Although I am not sure in what form the NSArray objects are stored (because of the IDL part involved).
I apologize for miscommunication if any, but I thought that it was imminent that I was talking about 'reference' to an object. I think my reference to 'reinterpret_cast' should have made the things clear.
I'm not even sure you're trying this the right way. {"(mystruct *)
someobject;" )} is not valid C, and neither valid Objective C.
Again, I am refering to a 'reference' to an object here (which is valid C).
you the struct type name, and you'd still have to do some work to
actually find at what offset in the object that struct starts.
This is exactly the part that I want to figure out. I don't know at what offset the struct starts.
Any help would be appreciated.
Thanks in advance.
"M. Uli Kusterer" <email@hidden> wrote:
At 0:15 Uhr -0800 15.02.2005, SGGSCC-BIT wrote:
>Now, I want the data in a list of "mystruct" objects. That means(i
>presume) I will have to convert from type "NSObject" to "mystruct".
> I have tried using implicit and explicit {"(mystruct *)
>someobject;" )} casting but it doesn't work. I tried using [NSObject
>poseAsClass] function, but it didn't work either. I think I will
>need something like the "reinterpret_cast" of C++. Kindly let me
>know how to go about it. Am I missing something trivial?
It doesn't work that way. You can't just cast an object to a struct.
I think there is a way to get at the "struct" portion of an NSObject
(something like @struct or @ivars or so -- see Apple's ObjC.pdf book
to find out what it's really called), but that will IIRC just give
you the struct type name, and you'd still!
have to
do some work to
actually find at what offset in the object that struct starts.
I'm not even sure you're trying this the right way. {"(mystruct *)
someobject;" )} is not valid C, and neither valid Objective C.
So, not knowing what you're doing and without additional information
(give us additional information, and we may be able to help you
better), I can only perform vague guesses which, even should they
work for you, will probably not be a good (and definitely not the
best way) to achieve what you want. But anyway, here goes:
As a last resort, you could loop over your NSArray and manually
extract the data from it, and manually build a struct of the type you
need and copy the data from the objects into that.
However, unless you tell us what your NSArray and the objects in it
look like, and what the struct you need to generate looks like, we
can't really give you any useful help.
However, poseAsClass !
is not at
Do you Yahoo!?
The all-new My Yahoo! Get yours free!
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden