1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

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

Discussion in 'Mac Programming' started by Acorn, Jul 1, 2011.

  1. macrumors 68020


    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.
  2. macrumors newbie

    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!
  3. macrumors 68020


    ok thanks for the info Mac OS
  4. macrumors 6502a

    Short Answer: Yes

    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.
  5. macrumors 6502

    Madd the Sane

    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.
  6. macrumors 65816


    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.
  7. macrumors 6502

    Madd the Sane

    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.
  8. macrumors 6502

    Also, check out this nice overview: From C++ to Objective-C. Also, know that you can mix both languages in a single source file.
  9. Moderator


    Staff Member

    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.
  10. macrumors 6502a


    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.
  11. duggram, Jul 7, 2011
    Last edited: Jul 7, 2011

    macrumors 6502


    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?
  12. macrumors 6502a

    Steve says: Cocoa!

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

    You must use Cocoa.
  13. macrumors regular

    Or curses. Screw the user.
  14. macrumors 6502

    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).
  15. macrumors 6502a


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

    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.
  17. Yair1978, Jul 10, 2011
    Last edited: Jul 10, 2011

    macrumors newbie

    What??? But.......

    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....

  18. Moderator


    Staff Member

    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...

  19. macrumors newbie

    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"...

  20. Moderator


    Staff Member

    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).


    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.


Share This Page