PDA

View Full Version : Mixing Carbon & Cocoa




floyde
Jun 1, 2006, 06:17 PM
I was writing an AppleScript manager class using this example (http://www.cocoadev.com/index.pl?CallAppleScriptFunction) (the one by BenoitMarchal). I basically needed a method that could call an AppleScript function with parameters. The author said that it was the way to do it with Cocoa, but he used some Carbon-only constants (ie kASAppleScriptSuite, kASSubroutineEvent, etc.). Since Cocoa doesn't seem to have those constants, I added the Carbon header in order to be able to compile the code under my Cocoa plugin.

Is this a bad practice? Could it cause any problems in the future? Should I be looking for the Cocoa equivalents? thanks



savar
Jun 1, 2006, 07:55 PM
I was writing an AppleScript manager class using this example (http://www.cocoadev.com/index.pl?CallAppleScriptFunction) (the one by BenoitMarchal). I basically needed a method that could call an AppleScript function with parameters. The author said that it was the way to do it with Cocoa, but he used some Carbon-only constants (ie kASAppleScriptSuite, kASSubroutineEvent, etc.). Since Cocoa doesn't seem to have those constants, I added the Carbon header in order to be able to compile the code under my Cocoa plugin.

Is this a bad practice? Could it cause any problems in the future? Should I be looking for the Cocoa equivalents? thanks

I don't know if there's a Cocoa equivalent, but there's nothing wrong with mixing Carbon and Cocoa. A lot of times Carbon is still the only way to get something done. And you did it the right way, too: include the header and link against the library. Just because you link against it doesn't mean it copies all the Carbon APIs into your app and bloats it or slows it down or anything like that, so don't sweat it.

floyde
Jun 1, 2006, 08:32 PM
And you did it the right way, too: include the header and link against the library.
Mmm... I think I only included the header but I didn't link against the library :o (if that means that it should appear under the "Linked Frameworks" section of the project window). Should I link it as well? thx

GeeYouEye
Jun 2, 2006, 03:25 AM
Yes.

And I'll reiterate that there's nothing wrong with using Carbon in Cocoa, or Cocoa in Carbon. They're two different API's, each with their own uses. They can be mixed without issue.

EDIT: although I think you may be incorrect about there not being a Cocoa equivalent for what you're looking for.