PDA

View Full Version : If I know c++ is it a givin that I have to learn objective c to program for mac




Acorn
Jul 1, 2011, 04:06 PM
Ive been using c++ for the past couple of years and was wondering if i wanted to program for mac does that mean I have to switch to objective c.



Mac OS
Jul 1, 2011, 04:26 PM
That will depend on what you are planning to accomplish on the Mac.

You can build non-GUI applications entirely in C++ just like you would in any other environment. Xcode, Apple's IDE, fully supports C++ (as well as Obj-C++, a combination of both languages, albeit with some limitations).

You can also build GUI apps using C++ exclusively, but you will probably want to take advantage of all the APIs Cocoa, Mac OS X's native programming platform, has to offer. Most Cocoa's APIs, including the APIs that deal with the GUI, are based on Obj-C. You can try to use "bridges" to access the Cocoa APIs using C++. IMHO, given that both are C-based languages, it shouldn't take you more than a couple of months to master Obj-C if you are fluent in C++. Everything's pretty simple in Obj-C, save some aspects of its dynamic runtime that are not possible in C++. By using Obj-C, you'll make Apple happy, and you'll make sure your code will work in the future.

Good Luck!

Acorn
Jul 1, 2011, 04:47 PM
ok thanks for the info Mac OS

PatrickCocoa
Jul 1, 2011, 08:31 PM
Long Answer: Yes, you do need to learn Objective-C.

Longer Answer: Yes, you do need to learn Objective-C, it will be easier in the long run than trying to shoehorn your current knowledge into the Mac world.

Madd the Sane
Jul 6, 2011, 01:07 AM
Wirelessly posted (Mozilla/5.0 (iPod; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5)

If you use WxWidgets, Apple does supply a version on Mac OS X. However, the version bundled with Snow Leopard uses Carbon APIs, and thus limited to 32-bit apps. You can compile a beta version that uses Cocoa, but you have to explicitly tell it to do Cocoa or it'll do Carbon.
If you want to do some serious app development on OS X, I reccomend learning Objective C. It's not hard to learn, and will make your apps more Mac-friendly.

jiminaus
Jul 6, 2011, 01:55 AM
Apple does supply a version on Mac OS X.

Really? Apple supplies it?! That's news to me. AFAIK it's not installed by default on Mac OS X and you have to install the Mac OS X port yourself.

Madd the Sane
Jul 6, 2011, 02:02 AM
Wirelessly posted (Mozilla/5.0 (iPod; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5)

Just look in the /usr/lib/ for it. It also includes the configure script to help you build (wx-config), but I think the headers are installed with Xcode.

Sander
Jul 6, 2011, 03:18 AM
Also, check out this nice overview: From C++ to Objective-C (http://chachatelier.fr/programmation/fichiers/cpp-objc-en.pdf). Also, know that you can mix both languages in a single source file.

robbieduncan
Jul 6, 2011, 04:55 AM
Also, check out this nice overview: From C++ to Objective-C (http://chachatelier.fr/programmation/fichiers/cpp-objc-en.pdf). Also, know that you can mix both languages in a single source file.

Exactly. If you use Objective-C++ you can keep the core logic in C++ and only have a thin wrapper of Objective-C for the UI.

GorillaPaws
Jul 6, 2011, 08:43 AM
If you know C++, then learning Objective-C will be a breeze (it's just a small extension to the C language). The thing that takes time is learning the Cocoa Frameworks, and there's really no getting around that if you want to write an attractive native Cocoa app.

duggram
Jul 7, 2011, 11:24 PM
What about using CodeBlocks and WxSmith? Does it really create cross platform C++ apps? Anyone with experience?

What I'm trying to ask is, can you do Mac application development using CodeBlocks?

PatrickCocoa
Jul 7, 2011, 11:47 PM
What about using CodeBlocks and WxSmith? Does it really create cross platform C++ apps? Anyone with experience?

What I'm trying to ask is, can you do Mac application development using CodeBlocks?

Mac users expect (or demand) "Mac-like" applications. Mac users hate cross platform apps.

You must use Cocoa.

ehoui
Jul 8, 2011, 08:21 AM
What about using CodeBlocks and WxSmith? Does it really create cross platform C++ apps? Anyone with experience?

What I'm trying to ask is, can you do Mac application development using CodeBlocks?

Or curses. Screw the user.

Mac_Max
Jul 8, 2011, 02:48 PM
Cocoa isn't necessary and in all honesty I suggest using the Obj C++ approach as much as possible unless its only going to be a Mac only piece of software. Lots of Mac GUIs are made using QT, GTK, and even with C#/WinForms/GTK/QT care of Mono. I believe you can find example programs on the respective sites of those toolkits.

Some do better than others at following UI standards and others intentionally throw them to the wind in order to have a unique and consistent UI across conflicting platform standards (i.e. emulating an MFC MDI type app on the Mac because the Windows and Linux versions work that way).

GorillaPaws
Jul 9, 2011, 07:34 PM
Lots of Mac GUIs are made using QT, GTK, and even with C#/WinForms/GTK/QT care of Mono. I believe you can find example programs on the respective sites of those toolkits.

Can you give some examples of apps that have done this well, and provide a quality end-user experience?

mdatwood
Jul 9, 2011, 08:57 PM
If you know C++, then learning Objective-C will be a breeze (it's just a small extension to the C language). The thing that takes time is learning the Cocoa Frameworks, and there's really no getting around that if you want to write an attractive native Cocoa app.

QFT. Obj-C is an easy language for anyone with C experience and some OO under their belt. The hard part of OSX/iOS development is not obj-c, but learning all the frameworks.

Yair1978
Jul 10, 2011, 12:12 PM
I'm returning to programming after some 10 years. Then I mastered basic Pascal and C and I've decided to try to get back into things. My natural choice was c++, as I'm under the perception that this language is pretty basic to many other languages as well as still widely used.

Now, I have a Mac.... But I don't really want to learn anything that's ONLY for Mac, but still I want to do my learning on the Mac... Should this be such a problem? Learning C++ on a Mac? Is there no way to at least build simple GUI applications using C++ on a Mac?

Please note that my question is a bit different from the original one. I'm not a programmer who's already savvy in C++ and who wants to develop for Mac. I want to get into programming....

/Yair

balamw
Jul 10, 2011, 12:21 PM
Is there no way to at least build simple GUI applications using C++ on a Mac?

The problem is that GUI APIs are platform specific. For your own consumption Qt or some other third party "middleware" framework would do, but these apps tend not to look like real "native" Mac apps as previously discussed in the thread.

One big thing to learn as far as GUI programming goes is to separate your code into parts. The UI should be separate from the code that actually does "the work". Apple's Cocoa and Objective-C reinforce this by pushing Model/View/Controller (MVC) http://en.wikipedia.org/wiki/Model–view–controller throughout.

This allows you to make the model portable, potentially in C++, and to write a GUI on top of that in Objective-C for OS X or C# for Windows...

B

Yair1978
Jul 10, 2011, 12:29 PM
The problem is that GUI APIs are platform specific. For your own consumption Qt or some other third party "middleware" framework would do, but these apps tend not to look like real "native" Mac apps as previously discussed in the thread.


Thank you for the answer!

Just a few more clarifications, though... ;-)

1. Just to get into programming then, am I going at it backwards starting off with c++ on my Mac? Should I just change language (perhaps Java, then?) or change platform (have Windows through Bootcamp, just that it's annyoing to have to reboot).

2. If I do choose to stick with my original plan (c++ and my Mac), will xCode not do the job? All tutorials seem to start off with doing a "hello world" through a console application, which is not really where I necessarily want to be "stuck"...

/Yair

balamw
Jul 10, 2011, 12:35 PM
IMHO if you are going to focus on GUI programs you need to pick one of two paths.

Learn a cross-platform UI framework and library and use that knowing that your apps will never seem perfectly native, and native programs will also outperform it. (Java fits in here too).

or

Pick a platform and environment and learn the language most appropriate for that platform. If that's Mac learn Objective-C/Cocoa in Xcode, for Windows I'd pick C# in Visual Studio.

It really depends a lot on where you want to go with this and what kind of applications you want to develop.

B