Re: Call Cocoa from C++
Re: Call Cocoa from C++
- Subject: Re: Call Cocoa from C++
- From: Uli Kusterer <email@hidden>
- Date: Thu, 24 Dec 2009 10:28:18 +0100
On 17.12.2009, at 20:24, Randall Meadows wrote:
> Just like that. Put this into a .mm file, and it'll compile as Objective-C++. You'll get a compiler warning that objcptr may not respond to updateText, which you can eliminate by casting objcptr to the appropriate class.
By the way, neat trick:
The header <objc/objc.h> is a C-language header implementing the runtime. It defines some standard types used by Objective-C, including id. So if you include this, your headers can use the "id" data type even if they're included from plain C++ or C files. I.e. your header and source file would be:
// MyClass.h
#include <objc/objc.h>
class MyClass
{
public:
id objcptr; // ptr to my obj-c object
void CallOBJC(void);
}
// MyClass.mm
MyClass::CallOBJC()
{
[objcptr updateText];
}
You can't ObjC-style qualify the "id" with a category, as in "id<MyUpdateTextProtocol>", but it's a tad more elegant.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.lookandfeelcast.com
_______________________________________________
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