Re: Cocoa Classes from C++?
Re: Cocoa Classes from C++?
- Subject: Re: Cocoa Classes from C++?
- From: Todd Heberlein <email@hidden>
- Date: Tue, 27 May 2008 16:50:45 -0700
On Tuesday, May 27, 2008, at 04:32PM, "Jens Alfke" <email@hidden> wrote:
>We did that the PubSub framework and it works fine, actually. You just
>have to check the "Call C++ Ctors/Dtors in Obj-C" build option in
>Xcode.
Ooh, I can learn something every day in these mailing lists. :-)
Just to add my $0.02...
I write all my libraries in clean C++ for portability, because I am comfortable in C++ and I have a lot of legacy code in C++. Then I build Objective-C objects when I build a Cocoa-based app, and I embed the C++ objects as needed into the Objective-C objects. For the most part, everything is painless.
The gotchas that I often run into are: (1) Changing an Objective-C file to an Objective-C++ object (by renaming it to a .mm file) often causes me to rename a lot of files to .mm, because if the Objective-C class definition has a C++ object in it, every source code file that includes that Objective-C class definition needs to be renamed to a .mm file; (2) I always declare my C++ objects in Objective-C classes as pointers, and then in the init method I allocate the C++ object; (3) I often have two container classes for some content -- one in C++ used in my libraries and one in Objective-C so I can connect it to the GUI (e.g., via a controller), so I need to do a little work to keep them consistent.
Todd
_______________________________________________
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