• 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: Call Cocoa from C++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Call Cocoa from C++ (From: David Blanton <email@hidden>)
 >Re: Call Cocoa from C++ (From: Randall Meadows <email@hidden>)

  • Prev by Date: Adding sub menus programatically
  • Next by Date: Re: NSCollectionView NSArrayController bindings from outer hell
  • Previous by thread: Re: Call Cocoa from C++
  • Next by thread: understanding the column of a double clicking into a table view
  • Index(es):
    • Date
    • Thread