How to learn Cocoa

Monday, December 18th, 2006

Every so often on forums or mailing lists I see someone ask the question, “how do I learn Cocoa?” There’s no short answer, and rather than try to type out a reply each time the subject is brought up, I’m going to expand on it a bit here. Even though there’s no right path for everyone, I can give some tips and advice from my own experience. Read on if you feel overwhelmed, or just don’t know where to begin.

Do the Currency Converter Tutorial

Before you write a single line of code you need to get familiar with the basic tools for programming in OSX. If you’ve never set foot in Xcode or Interface Builder, Apple’s Currency Converter tutorial is just the thing you need. It will also introduce you to those [ ] braces that seem so weird at first if you’re coming from a different language.

Learn about Memory Management

Whether you’ve dealt with memory management in other languages or not, Objective-C’s retain release pattern probably isn’t going to be familiar. It’s not something to worry about though, memory management in Objective-C is easy to learn, and works well in practice. Most tutorials are going to be roughly the same, but you can go here or here for starters.

Know your Resources

Part of programming any language is knowing where to go to get help and information. In addition to the built-in API documentation there are some great community resources out there, and I’d suggest visiting them each time you sit down to code, if not daily. A few that have been indispensable to me are Apple Developer Connection, the CocoaDev Wiki, and the Cocoabuilder Mailing List Archive.

It’s also a great idea to become active in the Cocoa developer community. In addition to providing interesting daily reading, you’re bound to pick up useful little tricks and hints that aren’t publicized elsewhere. Apple’s Cocoa-dev Mailing List, and OmniGroup’s MacOSX-Dev Mailing List are both active centers for discussion. Blogs, from both small and large development companies, are also a good source of information (although I assume if you’re reading this, you already know that). Take a look around Cocoa Blogs for starters.

If this is your first introduction to programming, you might want to read through CocoaLab’s Become an Xcoder e-book, which covers the basics using the OSX environment. Also, Cocoa Dev Central’s Tutorials are extremely helpful and well-written, for beginners and experienced programmers both.

Forget about Bindings

Maybe you’ve heard about these neat new technologies like Bindings and Core Data, and you’re thinking you don’t have to worry about things like data source methods because they’re the “old fashioned” way. Well, forget it. Bindings saves you a lot of work, but it’s no replacement for understanding how things work at a lower level. In fact, once you start writing a real world application using bindings, you’ll almost always need to use a trick or two to get them working, and that requires an intimate knowledge of key value coding and object handling. Learn the basics first, and save bindings and Core Data until they’re really needed.

Buy Hillegass’ Book

Cocoa Programming for Mac OSX is one of the best Cocoa books you can buy. Even though most programmers recommend it as the first step in learning Cocoa, I’m leaving it towards the end here. It’s not because Hillegass doesn’t teach you the basics of Cocoa programming, but because the majority of the book focuses on more advanced topics such as writing a subclass of NSView, or working with the responder chain. If you already know the fundamentals behind Cocoa and are enthusiastic about using those skills to write a real application, you’re going to get a lot more out of this book than using it as your first and only resource.

Explore the Frameworks

Believe it or not, Cocoa programming doesn’t just involve Cocoa. There is a lot of functionality hidden away /System/Library/Frameworks that isn’t included in a new Cocoa project by default. You can find everything from CD burning to working with Open GL, and they can do a lot of the heavy lifting for you. Best of all, there are no restrictive licensing issues or huge price tags involved.

Write your own Dream App

You can read as many tutorials and books as you want, but there’s simply no substitute for writing code. It doesn’t matter if your idea sucks, the code you write is terrible, or if the end result doesn’t always work correctly (assuming you finish it at all). As long as you’re working on something, you’re going to end up running into new challenges, gaining experience and learning new concepts. And in my experience, that’s simply the best way to improve your skill set, no matter what language you’re working in.

There are 9 comments in this article:

  1. 18/12/2006Scott Stevenson said:

    Good stuff overall, though I don’t agree with positioning Bindings as a second-tier skill. Certainly you need to understand accessors first, but I think learning table view datasource methods is essentially a waste of time at this point.

    I completely agree writing code is the most valuable thing you can do is just start writing code — any code at all.

    Dude, where’s the shout out to watching Cocoa Blogs to see what other Mac programmers are up to? Not just trying to be clever, I think watching other developers is absolutely invaluable. It helps you cut through theory and find out what matters in real-world cases.

  2. 19/12/2006Marc Charbonneau said:

    Thanks Scott! I’ve added a link to Cocoa Blogs to the article.

  3. 19/12/2006Jan said:

    just a note: the memory management tutorial links are quite similar, or do I miss a joke here?

  4. 19/12/2006Jan said:

    Now that I read the entire article I can make a useful comment :-)
    Open Source projects are another treasure of information. If an Open Source app does something that you want in Your Dream Up, just look it (but beware licensing). I learned quite a bit from Richard’s DesktopManager, the iTerm project and Growl.

    The advice here would be: Read and understand code written by others. You learn about different ways to solve problems and when to use which approach.

  5. 19/12/2006Todd said:

    Nice article. As a Cocoa newb, it rings true for me.

    I think you have a point with the Bindings. I have been able to make some pretty interesting demo apps with only bindings. But, now I’m really struggling to figure out how to get to the underlying data & where to “plug in” as it’s being shuffled around.

  6. 19/12/2006Marc Charbonneau said:

    just a note: the memory management tutorial links are quite similar, or do I miss a joke here?

    Fixed; thanks for pointing that out.

  7. 6/04/2007How to learn Cocoa - Basics « xcoding said:

    [...] How to learn Cocoa - Basics Posted April 6, 2007 I found a nice article thats shows some useful tips how to learn Cocoa. [...]

  8. 20/09/2007Kuroko Project » protip: you see no protip here said:

    [...] that with How To Learn Cocoa, Cocoa Dev Central, and Apple’s own Cocoa Reference Library. All free, fairly well written, [...]

  9. 28/04/2008Ignacio Cases said:

    Nice post. Thank you!