New to Objective-C

Discussion in 'Mac Programming' started by Woutje, Jan 13, 2006.

  1. Woutje macrumors member

    Aug 21, 2005

    I'm new to Mac OS X and programming on this platform.
    Can anyone tell me which is the most widely used programming language for Mac? And what's so special about Objective-C? Are all apps made with Xcode? What's a good place to start learning the "recommended" language?

    I'd like to point out that I have experience in VB.NET, PHP, ASP.NET, JavaScript, ActionScript, and that's about it...
  2. Nermal Moderator


    Staff Member

    Dec 7, 2002
    New Zealand
    My current experience is very similar to yours. I've been using .NET since the betas, I didn't switch to Mac until 2003. I still have a Windows PC with VB and ASP 2005, and I'm relatively proficient with them. Xcode, on the other hand, is significantly different, and to be perfectly honest, I simply can't get my head around it :(

    So, for the benefit of both of us, does anyone know of a "switch from VB.NET to Xcode" guide?

    Edit: After reading that back to myself, I sound like Rimmer from Red Dwarf :p

    "After intensive investigation, of the markings on the alien pod, it has become clear, to me, that we are dealing, with a species of awesome intellect:"

    "Good. Perhaps they might be able to give you a hand with your punctuation."
  3. atari1356 macrumors 68000


    Feb 27, 2004
    Objective-C is the primary language of choice if you want to create Mac applications. Apple has an extensive library of frameworks called Cocoa that can be used along with Objective-C to do alot of the dirty work of creating an application like drawing windows, handling menus, passing information from text field objects, etc.

    You can also use other languages, like Java or Python... but I believe Objective-C is still the most commonly used.

    There's a ton of info available on the Apple developer site:
  4. wala macrumors member

    Jun 3, 2005
    Objective-C's been picked by Apple because it has a strong level of object orientation and is relatively easy to learn. Xcode is Apple's home brewed development environment, used to make everything from Automator actions to Mac OS X itself. Though Objective-C is the recommended language to pursue OS X development with, Xcode also supports AppleScript, C, C++, and Java.

    I haven't had experience in all the languages you mentioned, but to me JavaScript is most like a C dialect, at least in syntax.

    There are other environments such as REALbasic, which claim support for porting VB projects, for instance, to the Mac.

    I am in the process of learning the basics of Objective-C, and am currently reading Steve Kochan's book, perhaps one of the best references out there.
  5. Damien macrumors regular

    Mar 2, 2004
    I cant find that book, and the author is not on amazon? You have a IBSN

    I really want a goood book on Cocca/Objective C and also on xcode which confuses the helll out of me. Introduction to p[rogramming on the mac kinda things
  6. caveman_uk Guest


    Feb 17, 2003
    Hitchin, Herts, UK
    The Kochan book is on Amazon UK here

    The other good introductory book for mac programming is this one. This one deals more with the Cocoa frameworks whereas Kochan's deals more with the language. They are both excellent books and I'd recommend getting both as they are different.

    Sadly the books available on xcode aren't that great but this book looks interesting. It's not on amazon though.
  7. Damien macrumors regular

    Mar 2, 2004
    xcode has an awful awful interface. I really wish it was better documented
  8. caveman_uk Guest


    Feb 17, 2003
    Hitchin, Herts, UK
    It's a very powerful tool that tries to do a lot of things. The interface isn't that bad except it can take you a while to find stuff if you don't know where it is. I think it would be a good idea if interface builder wasn't a separate app though.
  9. AlmostThere macrumors 6502a

    Recommended for what?

    What is the "recommended language" for Windows? C, C++, C#, VB, J#, ASP, SQL ... horses for courses and all that.

    Cocoa and Objective-C are probably (and this is by no means anything other than a ballpark approximation) around managed C++ / C# area of Windows development, pushed pretty hard by the company, capable of just about anything but can be painful to develop with (compared with say VB).

    If you want a RAD GUI building environment, the closest is probably Python through PyObjC, which although officially recognised and used by Apple is not officially supported.

    But, as you already know the above languages, you will no doubt be aware that they can be used for similar tasks and that there is functional overlap and that each has it's own strength and weakness.

    You could do worse than checking out dashboard widget programming (assuming you are on Tiger) which means you can leverage your JavaScript.

    IIRC, PHP is installed by default, so you can dive into that straight away and likely take your projects straight over.
  10. savar macrumors 68000


    Jun 6, 2003
    District of Columbia
    Most are written in C or Obj-C. There's nothing "special" about the latter except that the Cocoa API is written in it, and you probably want to be writing Cocoa apps (unless you need cross-platform compatibility). Most apps are made with Xcode. The alternatives are MetroWorks (which is nearly dead) or writing a custom makefile. Xcode hosts the vast majority of OS X development.

    There's a book by Aaron Hillegass on Cocoa and most people generally agree that its the best. I actually lost my copy and will probably buy a new one because its extremely good. It teaches you Obj-C in the first couple of chapters, which suffices if you know C.

    Your development experience should pay, but it would be helpful to be comfortable with C and with object-oriented design. (I don't know if VB.NET or ASP.NET are OO, but the others you mention are not very OO.) Obj-C isn't really hardcore OO (it's not like SmallTalk), but it would help to understand the basics.
  11. Damien macrumors regular

    Mar 2, 2004
    Can some explain the different between a coding lanauage ala Obj - C and Cocoa?

    What exactly is Cocoa?
  12. AlmostThere macrumors 6502a

    Common functions used in programmes such as opening a file, dividing a sentence in words, drawing in a window are built into what are called libraries. There are many different libraries around often overlapping in functionality and specialised ones for graphics, sound, math, you name it.

    Normally when writing a programme, you call on one of these libraries rather than writing your own code, to build your own programme - modern computer programming is built entirely around the different layers that different people have built. I might want to draw a filled square on the screen but I have no intention of researching block filling algorithms or device drivers. I just want to write something like fill_square_at_coordinates(100, 100).

    This same functionality often wants to be made available to a large number of languages - while different languages are used for different tasks there is also a lot of similarity. It is neither useful nor practical and sometimes not even possible to rewrite functionality in different languages.

    So what happens is a developer will write what is often termed as a set of bindings to a library for different languages each of which offers an interface, i.e. a way for a programmer to access that functionality.

    To return to the question, Cocoa is basically a large set of libraries offering a whole host of functionality with an Objective-C interface.
  13. Damien macrumors regular

    Mar 2, 2004
    So its just a load of libraries?

    Why is there not just one for the mac? Why is there Carbon and Cocoa? Is this because they are too different to offer the same libraries
  14. AlmostThere macrumors 6502a

    Carbon and Cocoa use some of the same underlying libraries but offer different interfaces to it, e.g. Quicktime. Think of the complexity in dealing with all the multimedia file formats. It would be bonkers to write all this twice, so you write the actual library and then add a Carbon or Cocoa interface (roughly speaking).

    As Mac systems have evolved, so have the development tools. Cocoa came to the Mac from NextStep and brought with it a large library of functionality already found in Carbon - you can find much of this in GNUStep, an implementation found on Linux. Almost any user interface library is going to have methods for dealing with strings and images, for example. Apple are encouraging developers and expect new developers to use Cocoa.

    Carbon is in some ways a hangover from pre-OS X days but required because otherwise masses of existing software and developers would be lost. It was and probably still is a very high priority for Apple to maintain and develop. Carbon, like Cocoa, has it's own string and image functionality but from its own heritage, independent of Cocoa.

    (I have no doubt someone on these forums will have an encyclopaedic knowledge of all the gory details.)

    All operating systems offer a range of libraries that duplicate functionality to a certain extent and these also evolve just as hardware does.

    Windows for example has the "Win32" in C, "MFC" and "ATL" in C++ and now ".net" in all sorts of languages. The actual number of functions has risen from a few hundred to tens of thousands in this time - but, just as with Carbon and Cocoa, the more modern interface tends to offer more power for less actual programming. That's technology for you.
  15. AlmostThere macrumors 6502a

    Oh and it isn't just a load of libraries it is access to services and resources, too. Depending on who you ask, they might say it includes the tools as well AKA The Cocoa Environment.

    I would try not to get too bogged down in the tiny details unless you have a particular fetish for pedantry :)
  16. HiRez macrumors 603


    Jan 6, 2004
    Western US
    In a sense you could say it's mostly "just" a load of libraries. But these libraries let you do so many things without having to do everything yourself, so they are not only helpful but critical to modern programming. Let's say you want to open a blank window on screen. Without Cocoa, you'd have to allocate and dispose of the memory or all of the components of the window yourself, tell the computer how to draw every pixel of the window and its widgets, track user mouse and keyboard movements to know when she clicked on the close box, or dragged the window, or resized it, tell the computer how to redraw the window properly when other windows overlap it, etc. In short, it'd be a nightmare.

    By comparison, Cocoa can open a window on screen in a single line of code. When you create an editable text box in Cocoa you get cut, copy, and paste automatically, live spell-checking, and the ability to use mixed fonts, colors, and styles on the text. If you want the text to scroll with scrollbars you simply wrap it in an NSScrollView. If you want to format the text, make a single call to add a ruler. You can make a basic word processor with probably a dozen lines of code or so, thanks to the Cocoa API. Another example is the Cocoa Document architecture where you can have a launchable application with working menus and multiple document windows without writing a single line of code. Loading a file into memory as a data array (with automatic buffering and cacheing) is a single line of code, as is displaying an image or movie in pretty much any format.

    So Cocoa does a lot for you. My biggest gripe is that Cocoa just doesn't cover enough of everything you might want to do on a Mac as a programmer yet. If you want to use QuickTime (the majority of it) or CoreAudio using nothing but Objective-C and Cocoa, you're basically out of luck. If you want to retrieve video data from a camera attached to a FireWire port, forget it. But, Apple is (slowly) adding some Cocoa "wrappers" for these types of things, like WebKit and QTKit. And the NSSound object now supposedly uses CoreAudio behind the scenes, although its functionality is very limited. You'll still have to do some down-and-dirty coding at some point with straight C, or possibly C++/Carbon/other, but at least Cocoa makes it easy to take care of the basic stuff that is common to most applications (windows, buttons, menus, strings, arrays, event handling, etc.) so you don't have to worry about all the details.
  17. Catfish_Man macrumors 68030


    Sep 13, 2001
    Portland, OR
    Cocoa is an Objective-C API descended from NeXTStep, Carbon is a C API descended from MacOS. There are lots of other APIs on OSX as well; mach, bsd, etc...

    Windows also has tons; WinFX, Win32, Windows.forms, MFC, DirectX, and so on.

Share This Page