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

C and GUI

Discussion in 'Mac Programming' started by laur5730, Oct 30, 2009.

  1. macrumors newbie

    #1
    This is the ultimate noob question, hehe.

    I'm currently learning to write C so I can move over to Objective-C.
    What I want to ask is, can you make C work with a GUI or do I have to wait with Objective-C and Cocoa? :)

    Thanks in advance

    P.S. Another inc noob question.
    Is there different on Windows C and Mac C?
     
  2. macrumors regular

    #2
    If your objective is to learn objective c, why not start with that?
     
  3. macrumors newbie

    #3
    > I'm currently learning to write C so I can move over to
    > Objective-C. What I want to ask is, can you make C work
    > with a GUI or do I have to wait with Objective-C and Cocoa? :)

    If you want to learn Objective-C, then just start out learning Objective-C. You will learn the parts of C that you need to know at the same time. Starting out learning plain C will actually make learning Objective-C somewhat harder because the paradigm shift from procedural based programming to object oriented programming will be a more difficult mental transition for you to make than if you just started off learning Objective-C's system of object oriented programming right away.

    You can use Carbon to write a GUI in C on Mac, but I would strongly advise against it. Carbon is deprecated and will no longer be enhanced by Apple.

    As far as other options for developing GUI on Mac, yes there are plenty. There are several C++ options such at Qt. There are also other languages such as Python or Java. These would make your app more portable as Objective-C and Cocoa are tied exclusively to Apple for the most part.

    > Is there different on Windows C and Mac C?

    As far as the language and standard C library, no there is not. But when you start getting into GUI development and such, then yes, the APIs are very different between Mac and Windows. However, if you go with a cross platform toolkit like Qt, you can hide almost all of the underlying API differences so you don't have to worry about them. Again, this will make your programs more portable if you are interested in running them on systems other than Macs.

    Hope that gives you some good information to get started with.
     
  4. macrumors newbie

    #4
    This is interesting :)

    My goal is to program for Mac/iPhone but mainly the iPhone. My track book reading was something like: Learn C on the Mac (which I should drop now), Learn Objective-C on the Mac, Beginning iPhone 3 Development: Exploring the iPhone SDK (the iPhone track) or Learn Cocoa on the Mac (the Mac track). Is there any book/better track you would take? :)

    But let me hear if I got this right (I'm still new to all this programming)
    C is same for Windows and Mac until I play with GUI.
    C++ is for Windows mostly/only
    Objective-C is for Mac mostly/only.

    But if I want to make a GUI for Objective-C (I want to focus on develop for Mac/iPhone as I can see all are doing for Windows = greater audience(you know what I mean :))) I should go with Cocoa.

    For example, the bot Pocket Gnome. I believe that is written in Objective-C with Cocoa as GUI? There picture is at top right :)

    Thanks in advance again!
     
  5. macrumors 6502a

    GorillaPaws

    #5
    I would personally recommend Kochan's "Programming Objective-C 2.0", and then Hillegass's "Cocoa Programming for Mac OS X." Hillegass doesn't cover the iPhone, but it's still a very good foundation to have. I haven't messed with the iPhone yet myself, so I can't make any suggestions as to which book is best for that (I'm sure there's threads on the subject in the iPhone development forum though-- might want to do a search).
     
  6. macrumors newbie

    #6
    Thanks, I also heard much about Hillegass, will look more into him.
     
  7. macrumors 6502a

    #7
    With a slight adjustment this is right: The core of C is the same everywhere (Windows, Mac, Linux, embedded, etc..., etc..., etc...). The whole purpose of creating C was so that the phone company (Bell) could develop their software once, then compile it for any vendor's hardware/os combination.

    However, most of programming does not use the core of C, but rather builds on libraries of code that others have created. These libraries can be very platform specific, especially ones that are created by OS vendors. Of these the GUI libraries are often the most platform dependent.

    Now as others have mentioned, there are third-party GUI libraries that work very hard to make it easy to port back and forth. But they never quite feel native to any one OS (since they have to make compromises).

    Here you have it wrong. C++ is a standard extension of C and is similarly used all over the place, including in MacOS X. Much of the lower levels of MacOS X is written in C++. However, the NeXT company was a big proponent of an alternate way of adding Object Orientation to C, and so helped flesh out Objective-C.

    With the systems Apple has in place you can even mix C, Objective-C, and C++ calls into the same file using a '.mm' extension, although you are likely to drive yourself batty doing this too much (because of the weird mix of memory semantics). I should note that by listing 'C' in that list I am being redundant, since Objective-C is a strict superset of C, and C++ is very nearly one too (there is some exception that slips my mind at the moment).

    Technically there are Objective-C compilers that will compile on any target OS, but while Objective-C is a nice language the real draw to using it on MacOS X is the beautiful and extensive library that Apple provides: Cocoa. Without Cocoa and the underlying Foundation (and other) frameworks it would be a waste of time to use Objective-C (the same can be said about any language without libraries). And with two odd exceptions (Cocotron and GNUStep) none of these libraries are available anywhere else than on MacOS X.

    So a better statement is that Objective-C is only used to any great degree where the Cocoa or CocoaTouch libraries are available: MacOS X and iPhone OS.
     
  8. macrumors newbie

    #8
    Isn't Cocoa the GUI when working with Mac and iPhone?
     
  9. Moderator

    robbieduncan

    Staff Member

    #9
    Technically it's CocoaTouch, not Cocoa. It shares some concepts and a few classes, but it's different.
     
  10. macrumors 68030

    Catfish_Man

    #10
    Almost all of Foundation is shared; AppKit is where most of the differences are.
     

Share This Page