# Cocoa with C++?



## shad0w (Sep 22, 2003)

Hi,

well, I'm new to software programming with mac osx (not software programming itself. ). I read the tutorial about Cocoa and Objective C and began to enjoy Cocoa. But I don't like Objective C, it's not very sensefull in my eyes (programmed in java and c++ before). Well, could anybody tell me if there's a way to control the nice cocoa interface with C++ code? I searched google, but couldn't find good tutorials or anything else. The apple site is mostly adept to Objective C and Java, so there's even no usefull information.

thanks for any help.


----------



## bootedbear (Sep 22, 2003)

As far as I know, Cocoa has bindings for only Objective C and Java.

bear


----------



## Lycander (Sep 23, 2003)

Go to http://developer.apple.com and do a search for Objective-C++. It's not what you think, you can only mix Obj-C/Cocoa with C++ to a certain extent. I've tried it before and didn't like it. I'm like you, a C++ guy and don't like Obj-C/Cocoa, so I don't think you'll like Obj-C++ either, I'm just gonna leave that up to you.


----------



## shad0w (Sep 23, 2003)

Hi,

thanks for the answers.

@Lycander: You're right, mixing Objective-C and C++ is not what I want to do.  The Cocoa framework could be loaded into a C++ project, but I couldn't find any way to interact with this framework. The only way, I think, is to hope apple will bring C++/Cocoa support to us soon. 

Is there any other way to build nice interfaces with C++ in osx?
Never coded any graphical interfaces, just some command line tools for school. 

regards


----------



## wiz (Sep 23, 2003)

well one thing is for sure.. less bugs wint obj-c / java.

cocoa apps tend to be better off than carbon apps


----------



## ljocampo (Sep 23, 2003)

I might be wrong but I think that is what Apple's new Xcode Project Interface is all about (letting you use the programming language of your chioce, including C++, to implement full Cocoa.


----------



## rhg (Sep 24, 2003)

Since I'm a Qt guy, I heartly recommend the Qt/MAC Free Edition:
http://www.trolltech.com/download/qt/mac.html

IMHO, this is the best C++ application framework ever, and it's cross-platform in addition.


----------



## cfleck (Sep 24, 2003)

does qt have its own look then on os x?  i have no idea how that works, but my concern is that it would look different.  does it?  what about speed?  is there any difference at all?  screenshots?


----------



## Captain Code (Sep 24, 2003)

You can mix Objective-C and C++ together in the same app, and you get Objective C++, but I have never tried it myself.

I don't know if there is anything coming in XCode that will let you interface with the Cocoa framework, but I hope there is.

I started from C++ as well, and Objective-C seemed really weird and kludgy, but the more I work with it, the more I get used to it.

The thing I hate the most is writing the controller classes all by hand, but that will change with XCode.  XCode will manage the controllers for you and, I assume also allow you to manually change things if you want.  This is going to make programming Objective-C much less annoying to program, and will let you spend more time on writing the View and Document classes which are the heart of the app.

Apple does listen to their developers, and I don't see any reason why they couldn't create C++ headers & libraries to include in our applications if enough people wanted it.


----------



## rhg (Sep 25, 2003)

Qt has switchable and customizable styles. The default style on Mac OS X is Aqua which looks and behaves exactly the same as the 'genuine' Aqua. Also, speed is not an issue, Qt is very fast.


----------



## Lycander (Sep 29, 2003)

If you want to know more about Qt/Mac, read my article I wrote for OSNews:

http://www.osnews.com/story.php?news_id=3929


----------



## lurk (Sep 29, 2003)

> _Originally posted by bootedbear _
> *As far as I know, Cocoa has bindings for only Objective C and Java.
> *



Unfortunately for you guys holding your breath for a C++ version of Cocoa you will either be waiting a long time or have to accept something like  a Cocoa light.

The problem is that much of the functionality and ease of use in Cocoa comes from the dynamic nature of Objective-C.  This level of dynamic  flexibility is explicitly forbidden in C++ as a basic design tenant of the language.  So any functionality in Cocoa which depends on those more dynamic features just won't map over to C++.

Just to illustrate an example one thing which is used to very good effect in Cocoa is the ability for an object to store an arbitrary method ( a selector ) and and another object (the target).   This is how you are able to have objects make other objects do things so easily in Cocoa by directly translating "when the user presses this button call this method on this object" into code in a generic way.  Because of the static nature of C++ you cannot express invoking an arbitrary method on an arbitrary object.  The C++ language requires that you must know both the method and the type (up to polymorphism) at the call site.

This is just one example.  The truth of the matter is that almost all the nice stuff in Cocoa is simply not expressible in a static language like C++.  In choosing C++ you are choosing static type analysis with better compiler errors and potentially faster method dispatch.  In choosing Objective-C you are choosing a dynamic OO system and Cocoa.  You cannot have your cake and eat it too in this situation.

-Eric


----------

