• 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: Casting from NSArray to a custom class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Casting from NSArray to a custom class


  • Subject: Re: Casting from NSArray to a custom class
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Tue, 15 Feb 2005 14:20:49 +0100

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 all intended to be used for purposes like these, and that leads me to suspect you haven't read the right docs so far, and it may be a better idea if you got a good book like Hillegass to get a firm understanding of ObjC before you try to do more involved stuff like this.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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
  • Follow-Ups:
    • Re: Casting from NSArray to a custom class
      • From: "newdev@yahoo" <email@hidden>
References: 
 >Casting from NSArray to a custom class (From: SGGSCC-BIT <email@hidden>)

  • Prev by Date: No new connections after exception on writeData:
  • Next by Date: Re: Implementing the Dock genie effect in windows
  • Previous by thread: Casting from NSArray to a custom class
  • Next by thread: Re: Casting from NSArray to a custom class
  • Index(es):
    • Date
    • Thread