Getting Started with Mac Programming

January 7th, 2010

Filed under: Cocoa, Mac Development | Be the first to comment!

A question that comes up often in Mac programming forums is “Where do I start?” I have gathered a bunch of information and put it in this post to answer this question. Hopefully this helps people new to Mac development and reduces the frequency of “Where do I start?” questions on the forums.

NOTE: The information in this post is for people writing Mac GUI applications, not games. You could write a Mac game without having to learn Objective-C and Cocoa. Getting started in game development would be a good topic for a future post.

Update for Lion and Xcode 4 Users (July 2011)

Mac OS X 10.7 does not include Xcode. Download Xcode from the Mac App Store. The version of Xcode on the Mac App Store includes the iPhone SDK. Xcode 4 integrates Interface Builder with Xcode. There is no separate Interface Builder application.

The Tools You Need

If you have a copy of Mac OS X, you have the tools you need to write Mac applications. Apple includes developer tools, the Xcode Tools, with every copy of Mac OS X. Insert your Mac OS X DVD. The Xcode installer is in the Optional Installs folder.

Apple constantly updates their developer tools. To get the latest version of Xcode, go to Apple’s developer site. You will have to sign up for a free ADC membership before you can download Xcode.

If you’re interested in iPhone development, download the iPhone SDK instead of Xcode. The iPhone SDK contains both the Xcode Tools and the iPhone SDK. If you download Xcode, then download the iPhone SDK at a later date, you’re downloading Xcode twice, and Xcode is a large download.

After installing Xcode you will have all the tools you need to write Mac applications. The tools you will use the most are Xcode and Interface Builder.

Xcode is an integrated development environment. You will use Xcode to write your source code and compile the source code into a Mac application. You will use Interface Builder to create the user interface for your applications.

Learning a Programming Language

Before you can write Mac applications, you must know a programming language. If you have never programmed before, you will have to learn one. What language should you learn?

If you’re serious about writing Mac applications, you should eventually learn Objective-C. The Cocoa framework uses Objective-C as well as the Cocoa Touch framework, which is used to write iPhone applications.

Your First Language

Should you learn Objective-C first? If you post this question on a Mac programming message board, you will generate a lot of heated responses. These responses generally fall into three camps.

Camp 1: Learn Objective-C first. You have to know Objective-C to write Cocoa applications so you should go ahead and learn Objective-C.

Camp 2: Learn C, then Objective-C. Objective-C is a superset of C. It takes C and adds support for object-oriented programming. By learning C, you’ll make progress towards learning Objective-C.

Camp 3: Learn a language like Python or Ruby first. C and Objective-C are too difficult for a beginner. Python and Ruby are easier to learn. Start with one of them. After you learn Python or Ruby, you can move on to Objective-C.

Which camp is right? It depends on you and how you plan on learning Objective-C. If you plan on learning Objective-C through online tutorials, Camp 2 is right. Most Objective-C tutorials assume you know C so you would have to learn C first to understand the tutorials.

If you plan on learning Objective-C through Stephen Kochan’s Objective-C book (Amazon link), Camp 1 is right. The book doesn’t assume you know C so you can use the book to learn Objective-C without learning C first.

If you start learning C or Objective-C and have a hard time understanding the material, Camp 3 is right. Start with another language and learn Objective-C later.

Resources for Learning Programming

The World Wide Web is full of programming tutorials. The following sites will give you a large collection of programming language tutorials:

Some of you will prefer learning programming from a book. You can find books on Mac programming, Python, and Ruby from the following publishers:

Three programming language books that would help someone interested in Mac programming are the following:

  • Learn C on the Mac by Dave Mark.
  • Learn Objective-C on the Mac by Mark Dalrymple and Scott Knaster. This book is a sequel of sorts to Learn C on the Mac and assumes you’ve read Learn C on the Mac.
  • Programming in Objective-C 2.0 by Stephen Kochan.

Learning Programming on a Mac

If you’re learning C or Objective-C, you can use Xcode to learn the language. Create a command-line tool project for each program you write. In Xcode 3.2 take the following steps to create a command-line tool project:

  1. Choose File > New Project in Xcode.
  2. Select Application under Mac OS X on the left side of the New Project Assistant.
  3. Select Command Line Tool at the top of the New Project Assistant.
  4. Pick your language from the Type pop-up menu. Choose Foundation for Objective-C.
  5. Click the Choose button.
  6. Name your project and pick a location to save it.
  7. Click the Save button.

Those of you running Xcode 4 should click the Next button after Step 3. The Choose button in Step 5 is named Next in Xcode 4. Step 6 is split in Xcode 4. You name the project when you pick a language.

For those of you running older versions of Xcode, create a Standard Tool project to learn C or a Foundation Tool project to learn Objective-C.

Some people think integrated development environments like Xcode hide too many details from beginning programmers, which hinders learning. They suggest beginners write their source code in a text editor and compile it from the Terminal application. For more information on compiling from the Terminal, read my Avoiding Xcode post.

If you’re learning Python or Ruby, I have good news. Mac OS X comes with Python and Ruby interpreters so you can start writing Python and Ruby programs right now. For Python and Ruby programming, I recommend using TextWrangler, which is a free text editor. You can write, run, and debug Python and Ruby programs inside TextWrangler. My TextWrangler and Interpreted Languages post has more information on using TextWrangler.

Learning Cocoa

After learning Objective-C, you can move on to learning Cocoa. Cocoa is Apple’s framework for writing GUI applications on Mac OS X. Cocoa is a large framework so prepare to spend a lot of time learning it.

Cocoa Books

When people ask for book recommendations on Mac programming message boards, the usual recommendation is Aaron Hillegass’ Cocoa Programming for Mac OS X (Amazon link). This book does a good job of teaching the fundamentals of Cocoa programming. Hillegass assumes the reader knows C so his book is not right for people completely new to programming.

Cocoa is becoming a hot topic for computer book publishers. You can find a lot of new and upcoming Cocoa books from the following publishers:

Cocoa Learning Resources

The biggest source for Cocoa documentation is Apple. You can read Apple’s documentation in Xcode by choosing Help > Developer Documentation. You can also read it online at Apple’s developer site.

Some other sites that will help you learn Cocoa are:

This list is obviously not exhaustive. Use your favorite search engine to find more resources for learning Cocoa development and learning programming in general.


Leave a Reply

Your email address will not be published. Required fields are marked *