Re: ObjC data structure for C++/ObjC++ objects?
Re: ObjC data structure for C++/ObjC++ objects?
- Subject: Re: ObjC data structure for C++/ObjC++ objects?
- From: "Michael Ash" <email@hidden>
- Date: Fri, 7 Nov 2008 22:29:42 -0500
On Fri, Nov 7, 2008 at 8:41 PM, Jonathan Bailey <email@hidden> wrote:
> Hi all -
>
> I am trying to find a way to create a dynamically-growable objective C
> data structure within objective C++ code, such as a
> NSMutableDictionary, that can store values that are pointers to an
> objective C++ or straight-up C++ object.
>
> NSMutableDictionary seems to only accept pointers to objective C
> objects, however, and not to arbitrary objects. This seems like a
> simple thing to do but I am a bit stumped. Does anyone know of a way
> to do this?
CFMutableDictionary will accept arbitrary pointers, and allows you to
provide callbacks so that it knows how to work with them.
As an added bonus, CFMutableDictionary is "toll-free bridged" to
NSMutableDictionary, meaning that you can simply cast the pointer and
use it. The bridging is not 100% with custom callbacks, as there are
parts of the NSMutableDictionary API which assume that you are storing
only Objective-C objects, but for dictionaries which actually are
storing Objective-C objects it's very useful. This also means that you
can store it in other Cocoa collections like NSArray, other
NSDictionaries, etc.
And note that if you're using Objective-C++, there's nothing
preventing you from using STL collections for this sort of thing, if
they do what you like.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden