Cocoa Programming for Mac OS X

Aaron Hillegass

Mentioned 80

A revision of the highly acclaimed introduction to Cocoa programming, updated for Mac OS X Leopard.

More on

Mentioned in questions and answers.

I'm primarily a C# developer and I've been tasked with "porting" functionality from a few apps to an iPhone app.

The functionality is simple enough, and a language is a language, so I thought, "sure, why not? This will be fun!" ...That is until I got a look at Objective C, which, to me, is ugly bordering on unreadable.

Given that my background is primarly C#, and I'm somewhat familiar with C++, where can I find a good guide tailored to my background to get me moving in Objective C?

The one and only tome I recommend for learning Objective-C for people coming to ObjC from really many backgrounds, is Kochan.

As others have suggested, MonoTouch may be the best option for you. Apple's section 3.3.1 notwithstanding, no MonoTouch apps have yet been rejected from the App Store, and you can always distribute MonoTouch apps through Enterprise distribution if that is your situation. If you don't want to step out of your comfort zone, stick with C#/.Net. That way you only have to learn a new UI framework.

That said, many good developers find that learning a new language is an opportunity to expand their thinking, beyond just being fun. Objective-C has a very interesting history and is (at least) part of the the inspiration for many "modern" languages. Objective-C's stated purpose was to make integrating software components easier, hence its interesting mix of static typing and dynamic message dispatch. Your comments suggest you've taken a rather harsh view of the language. Many of us have the same reaction to any new environment, language, etc. Give it time and you may find that the special features of Objective-C outweigh the "ugliness" you see now.

In terms of learning Objective-C, Aaron Hillegass' book is pretty much the bible. It's OS X-oriented, but you should be able to take the appropriate iOS bits from it. Also, Apple's Objective-C Programming Language guide is very good.

I've been learning Objective-C and Cocoa by working my way through the Hillegass book and it occurs to me that I might be better off using Objective-C++. Objective-C seems like the clear choice for developing UIs but I have a very strong C++ background and would love to develop application back-ends in C++ and use Objective-C++ to do the UI integration. But I wonder if Apple will keep developing Objective-C++ or will it become a dead end.

Is anyone out there using Objective-C++?

Disclaimer: I don't work or speak for Apple, so this is my opinion:

I can't speak for the major dev shops, but in my small group, we've used Objective-C++ both for integrating C++ libraries, and as you propose for writing backends in C++. As @alxp mentions, things like exception handling across the language boundary are painful, but with a little planning, most of these pains can be avoided. For experienced C++ devs, the gains can be well worth the pain.

In terms of support, I think you can assume that support in its current state won't go away any time soon. It's part of the GCC code base and the Clang toolchain (Apple's next compiler toolchain) fully supports Objective-C++. On the other hand, there isn't any official guarantee that Apple will continue to develop the integration—fixing some of the warts, for example.

For current projects, I would say that if using Objective-C++ provides benefit, it is safe to rely on the existing support and you should use it.

I want to do a little development in OSX and the iPhone. I've been a .Net/C# developer for years. I was wondering if there was anybody that had experience in both platforms that could tell me how they compare and contrast. I'd like to get an idea of what sort of learning curve I've got ahead of me.



First the bad:
I have done some Cocoa development in XCode. The first thing you will notice is that the IDE (XCode) isn't anywhere as intuitive, or nice in general, as Visual Studio. I really miss intellisense when working in XCode. The Apple developers will probably down-vote me for that statement. But coming from a .Net environment, that is what I really miss. So don't set your expectations too high and you won't be too disappointed. I am not trying to run XCode down, it just isn't as nice as Visual Studio.

Now the good:
The general architecture of a Cocoa project is very nice. I do wish .Net Winforms and WPF used MVC out of the box like Cocoa projects do. As long as you follow the MVC pattern you should do OK with your project. Everything I have done is in Objective C. You might pick up a book on that. I purchased Cocoa Programming for Mac OS X and thought it was pretty good. If you have any C in your background, it will look very familiar. From a C# prospective, the dot notation for classes is replaced with a message-sending notation similar to Tcl.

Get iTunes loaded on your machine and download the iPhone dev videos under iTunes U. You will also need to sign-up for the developer program at Apple and download the extra bits for XCode for the iPhone.

Hope that helps. I am by no means a pro Cocoa developer.

If you have some Cocoa/Objective-C background, then you can jump into iPhone development with the help of "Beginning iPhone Development" by Dave Mark and Jeff LaMarche:

It's very easy to follow, but the authors assume some prior knowledge of Objective-C (as stated on the back cover), so I'd recommend starting with the first five or six chapters of "Cocoa Programming for Mac OS X" by Aaron Hillegass, as noted by others previously.

Aaron has been using and teaching Objective-C and the frameworks now associated with Cocoa since his days at NeXT, and it shows. The material is really, really good.

While the bulk of the development techniques apply equally to the Mac and to the iPhone, some techniques apply only to the Mac (e.g., garbage collection, bindings, Core Data) and some apply only to the iPhone (e.g., multiple targets for one action).

If you want to pick up iPhone development really quickly and you're willing to invest some cash, Aaron's team can also teach you everything you need to know in a week, through classes at the Big Nerd Ranch. (The iPhone class always fills quickly, but if you happen to be in the Silicon Valley, there's still room in "iPhone for commuters" in January.)

(Click the classes tab for a schedule of what and when, including Ruby, Android, and more.)

While I personally prefer the options above, there are of course some free online options as well. Scott Stevenson has put an enormous amount of effort into Cocoa/Objective-C tutorials:

And Stanford has offered classes both in Mac development and in iPhone development, taught by Apple engineers, and has posted the class materials online:


Lastly, it seems that developers who come to Mac/iPhone development with a Windows background try to avoid Interface Builder (IB) and instead build the UI in code. I understand why – IB doesn't lay out everything that's going on in a nice code listing – but I strongly recommend against this strategy.

Mac/iPhone development is all about minimizing code. The less code you have to write, the less you have to maintain, and the less chance there is for a mistake. IB is great for minimizing the code needed for the UI.

Your C/C# background will serve you well. You'll find that Objective-C seems quite odd at first, but I suspect you'll come to appreciate its strengths, and you'll pick it up very quickly. Unlike C++, it's actually pretty straightforward.

I'd like to start experimenting with Cocoa and programming for Mac OSX. I'm not terribly concerned with Objective C syntax/constructs/bheaviors at this point, but more curious as to an efficient setup on in terms of an editor and/or IDE that will get me going quickly. Is there any IDE even remotely similar to Visual Studio (since that's where I've spent most of my time over the last 7 years) in terms of it's solution/project concept? Any other tools, tips, suggestions and/or resources to get up and experimenting quickly?

I'd like to avoid a lot of the intro stuff and get into things like "If you want to create an Mac desktop application, you can use Acme IDE and set up your project like this."

I was afraid Xcode was going to be the answer! :P I tried playing around with that -- literally just getting it off the DVD and just diving in with no idea what to expect (before I even knew that you used Objective C as the language). I figured, the wise guy that I am, that I could just sort of fumble around and get a simple app working ... wrong.

@Andrew - Thanks for the insight on those config settings. Based on my Xcode first impression, I think those may help.

I've been dabbling in Cocoa for the past couple years, and recently picked up Fritz Anderson's "Xcode 3 Unleashed." Highly recommended for getting into Xcode — especially with some of the big changes 3.0/Leopard brought.

Don't forget Hillegass' defacto Cocoa bible, "Cocoa Programming for Mac OS X - Third Edition."

I'd suggest you pick a fun little product and dive in. If you're looking for a book I'd suggest Cocoa Programming for Max OSX which is a very good introduction both to Objective-C and Cocoa.

XCode is pretty much the de facto IDE and free with OSX. It should be on your original install DVD. It's good but not as good as Visual Studio (sorry, it's really not).

As a long-time VS user I found the default XCode config a little odd and hard to adjust to, particularly the way a new floating window would open for every sourcefile. Some tweaks I found particularly helpful;

  • Settings/General -> All-In-One (unifies editor/debugger window)
  • Settings/General -> Open counterparts in same editor (single-window edit)
  • Settings/Debugging - "In Editor Debugger Controls"
  • Settings/Debugging - "Auto Clear Debug Console"
  • Settings/Key-binding - lots of binding to match VS (Ctrl+F5/Shift+F5,Shift+Home, Shift+End etc)

I find the debugger has some annoying issues such as breakpoints not correctly mapping to lines and exceptions aren't immediately trapped by the debugger. Nothing deal-breaking but a bit cumbersome.

I would recommend that you make use of the new property syntax that was introduced for Objective-C 2.0. They make for a heck of a lot less typing in many many places. They're limited to OSX 10.5 only though (yeah, language features are tied to OS versions which is a bit odd).

Also don't be fooled into downplaying the differences between C/C++ and Objective-C. They're very much related but ARE different languages. Try and start Objective-C without thinking about how you'd do X,Y,Z in C/C++. It'll make it a lot easier.

I am learning programming. I plan on learning C and Objective-C this summer. I bought the C for Dummies book but it is a complete waste of time. It's way too many pages! Are there any good books I should read? Or should I just learn C from websites? What would be the fastest way because I really want to learn it fast and start learning Objective-C too.

Thank you

Also, how long does it take to learn C? Until I move to Objective-C 2.0

Stanford University posts online the lectures, class notes, and assignments for CS193P (an iPhone development class). If you don't know C or Objective-C at all, it might be tough, but I highly recommend this if you intend to do iPhone development.

I think I've read every Cocoa and Objective-C book out there, and most enjoyed Aaron Hillegass' Cocoa Programming for Mac OS X.

For learning C, I highly recommend Learn C on the Mac, by Dave Mark. Not only is it aimed at beginners, but it also teaches you a lot about the important fundamentals of programming and computer science (e.g. data structures, recursion, etc.). It's very accessible, well-written, and easy to read. Plus, I found the examples engaging and interesting to work with. After that, if you really want to solidify your foundations in C, I'd recommend trying to moving on to The C Programming Language. It's a challenging book, so take it slowly. If you find yourself having too much trouble with it, I'd say you can just skip to Objective-C, and then come back to The C Programming Language later, once you've gained more familiarity with programming in general.

A lot of people will probably recommend The C Programming Language (a.k.a. "K&R") as your first book to read on C. No doubt it is a very well-written C book (and it's short too—only around 200 pages), but I'd say it'd be a little intimidating as a 12-year-old's first exposure to C: it's pretty dense and hardcore. You can tell that it's definitely aimed at an older audience with a strong background in computers/engineering. But nevertheless, if you already know the basics of programming, reading K&R will give you invaluable insight and understanding of C. You should definitely read it at some point in your programming endeavors.

Anyways, for Objective-C, if there's only one book I could recommend, it would most definitely be Cocoa Programming for Mac OS X, by Aaron Hillegass. It's really not that long (~400 pages or so, although I'd reckon that a lot of that is due to the number of illustrations in the book), and you can get some pretty cool projects up and running in an afternoon. It's very clear and easy to read, the examples are practical and interesting to follow, but most importantly, it's got this right blend of not being too intimidating while still managing to provide you with solid information. Plus, it'll teach you more than just Objective-C: I found that I had learned some very useful design patterns, for example, by learning how some of the components of Cocoa worked.

What is the best source to learn Cappuccino? I do "traditional" web development, but i'm very interested in this new framework. Please note that I have no knowledge of Objective-C.

I recently took up learning cappuccino. I found the Cappuccino Casts and the tutorials on, however, like you, I come from a web development background - not cocoa / desktop apps.

Following some online tutorials was good to a degree, but I felt I lacked fundamental knowledge about the Objective-C and Cocoa and Cappuccino is modelled so closely to it. I bough a copy of Aaron Hillegass' book called "Cocoa(R) Programming for Mac(R) OS X" here: which I felt really helped with my base understand of application development rather than traditional web development.

I would definitely recommend giving it a read, I worked my way through it in a few days and thought it gave enough knowledge to understand what all the Cappuccino stuf was about.

Do I really have to learn Objective-C to develop solid Mac Apps?

As Mac users tend to use only applications that have a nice (native) GUI, i don't think that Mono and GTK+ or any Java GUI (Swing) will fit their needs.

There are projects like Cocoa#, PyObjC and RubyCocoa, but are they ready for primetime?

So do I really have to learn Objective-C ? I would prefer a dynamic language.

No you don't have to learn cocoa however it is worth looking at because it is an incredibly powerful api and very well documented, if you already know C then its very easy (honestly it is - i know it looks daunting syntactically).

The problem with the bridged approach on OS X is it seems to be very immature and only really designed for people who are prepared to read the documentation associated with the main cocoa api.

In all honesty if you know c you will pick up the basics of obj-c with a book, the one by Arron Hilligas (spelling?!?!) is superb.

I'd love to learn Cocoa, it seems like the best systems language for Mac OS X.

Can you recommend any useful ways to learn the language? Books, websites, example projects or even classes to take?

Buy a book, open XCode, and write. Seriously, writing is the best way to learn Cocoa. In addition, I recommend Cocoa Programming for Mac OS X!

One of the best books I read about Cocoa is Cocoa (Developer Reference) by Richard Wentk

Cocoa Programming for Mac OS X is a great book that covers Objective-C and many of the frameworks that make up Cocoa. Most Cocoa programmers I know learned from this book (including myself). The third edition was released recently, so it's fairly up to date. Good luck.

Andy Matuschak has a great blog post that leads you through several good Cocoa tutorials, explaining why you are reading each one.

Cocoa Dev Central has loads of tutorials.

For books, I echo Dave and Phillip Bowden with Cocoa Programming for Mac OS X by Aaron Hillegass.

How long does it take for an experienced Windows programmer to learn writing simple software for Mac OS X?

Where does one start and what tools will be necessary?

THIS. I came from a Win32 API background programming lately a lot in C# and I was able to pick up on Objective-C and Cocoa very quickly by working through the book. You will be pleasantly surprised, the APIs are very rich and just wonderful. Reflection is a first class citizen which makes things very easy.

Xcode is of course free and available on your Mac OS X installation disk.

Edit: it took me about 2 weeks to come up to speed and write simple applications. I think this is because the language and API are easy to learn and use and Aaron Hillegass's book was a big help.

I seem to enjoy designing new UIViews and UIControls that implement their own -drawRect: method. This work well for me, especially when composed using UIViews in Interface Builder.

But composing them in Interface Builder is annoying because they just show up as boring plain rectangles.

It would be great if the views would actually render themselves as the built-in controls do.

Is there any way I can structure my project so that Interface Builder will render my custom views?

In order to do this, you actually have to create a plug-in for Interface Builder that uses your custom class. Once you create and install your plug-in, you will be able to drag and drop instances of your class (your view) onto another window/view/whatever just like any other control. To get started with creating IB Plug-Ins, please see the Interface Builder Plug-In Programming Guide. Also, I recommend taking a look at Aaron Hillegass's book, Cocoa Programming for Mac OS X. As well as being very well written and easy to understand, it has a chapter on creating your own IB Palette controls.

I was wondering if there is any tutorial out there on Key Value Coding and Key Value observing, which use simple classes to explain these concepts instead of using cocoa. Apple programming guides sucks on this matter :@

Correction: When i am referring to Cocoa here, i mean use of Interface Stuff, sorry for using the wrong word, it's just because i am new to this and may be not have understand of what's difference between Cocoa and Simple Objective C code. If someone can help me to what i should write there, that would be great.

Theocacao usually has good content like that. Here is their post on KVC. It's a relatively straightforward concept overall once you play with it a little. The Apple KVC Fundamentals page really isn't too bad either.

Edit: In response to itsaboutcode below: Well, I don't know of any real good info on KVO besides Apple's intro docs here. If you really want to do Cocoa programming, including KVC/KVO, I have to recommend you get the Hillegass book. It's become the standard text, and is really great for beginners and experience programmers alike. I don't know any good Cocoa programmers personally that don't have it.

For example, is still for OS X 10.4 Tiger, not 10.5 Leopard.. And that's the official Apple documentation for it..

The official PyObjC page is equally bad,

It's so bad it's baffling.. I'm considering learning Ruby primarily because the RubyCocoa stuff is so much better documented, and there's lots of decent tutorials ( for example), and because of the Shoes GUI toolkit..

Even this badly-auto-translated Japanese tutorial is more useful than the rest of the documentation I could find..

All I want to do is create fairly simple Python applications with Cocoa GUI's..
Can anyone shed light on the horrible documentation, or point me at some tutorials that don't just give you huge blocks of code and assume you know what NSThread.detachNewThreadSelector_toTarget_withObject_("queryController", self, None) does..?

I didn't know anything at all about Objective C or Cocoa (but plenty about Python), but I am now writing a rather complex application in PyObjc. How did I learn? I picked up Cocoa Programming for OSX and went through the whole book (a pretty quick process) using PyObjC. Just ignore anything about memory management and you'll pretty much be fine. The only caveat is that very occasionally you have to use a decorator like endSheetMethod (actually I think that's the only one I've hit):

def alertEnded_code_context_(self, alert, choice, context):

I know some Python and I'm really impressed by the language's ease of use. From what I've seen of Objective-C it looks a lot less pretty, but it seems to be the lingua franca for Mac OS X development (which means it has better documentation).

I'm thinking about starting Mac development - will using PyObjC+Python make me a second class citizen?


For one thing, as you note, all the documentation is written for Objective-C, which is a very different language.

One difference is method name. In Objective-C, when you send a message to (Python would say “call a method of”) an object, the method name (selector) and arguments are mixed:

NSURL *URL = /*…*/;
NSError *error = nil;

QTMovie *movie = [QTMovie movieWithURL:URL

This isn't possible in Python. Python's keyword arguments don't count as part of the method name, so if you did this:

movie = QTMovie.movieWithURL(URL, error = ???)

you would get an exception, because the QTMovie class has no method named movieWithURL; the message in the Objective-C example uses the selector movieWithURL:error:. movieWithURL: and movieWithURL would be two other selectors.

There's no way they can change this, because Python's keyword arguments aren't ordered. Suppose you have a hypothetical three-argument method:

foo =, bar=bar, baz=baz)

Now, this calls foo:bar:baz:, right?

Not so fast. Foo may also have a method named foo:baz:bar:. Because Python's keyword arguments aren't ordered, you may actually be calling that method. Likewise, if you tried to call foo:baz:bar:, you may actually end up calling foo:bar:baz:. In reality, this case is unlikely, but if it ever happens, you would be unable to reliably call either method.

So, in PyObjC, you would need to call the method like this:

movie = QTMovie.movieWithURL_error_(URL, ???)

You may be wondering about the ???. C doesn't allow multiple return values, so, in Objective-C, the error: argument takes a pointer to a pointer variable, and the method will store an object in that variable (this is called return-by-reference). Python doesn't have pointers, so the way the bridge handles arguments like this is that you pass None, and the method will (appear to) return a tuple. So the correct example is:

movie, error = QTMovie.movieWithURL_error_(URL, None)

You can see how even a simple example deviates from what documentation might show you in Objective-C.

There are other issues, such as the GIL. Cocoa apps are only going to get more concurrent, and you're going to want in on this, especially with tempting classes like NSOperation lying around. And the GIL is a serious liability, especially on multi-core machines. I say this as a Python guy myself (when not writing for Cocoa). As David Beazley demonstrates in that video, it's a cold, hard fact; there's no denying it.

So, if I were going to switch away from Objective-C for my apps, I would take up MacRuby. Unlike with PyObjC and RubyCocoa, messages to Cocoa objects don't cross the language bridge; it's a from-the-ground-up Ruby implementation in Cocoa, with language extensions to better support writing Cocoa code in it.

But that's too far ahead of you. You're just getting started. Start with Objective-C. Better to avoid all impedance mismatches between the language you're using and the one the documentation is written for by keeping them the same language.

Plus, you'll find some bugs (such as messages to deceased objects) harder to diagnose without knowledge of how Objective-C works. You will write these bugs as a new Cocoa programmer, regardless of which language you're writing the code in.

So, learn C, then learn Objective-C. A working knowledge of both shouldn't take more than a few weeks, and at the end of it, you'll be better prepared for everything else.

I won't go into how I learned C; suffice to say that I do not recommend the way I did it. I've heard that this book is good, but I've never owned nor read it. I do have this book, and can confirm that it's good, but it's also not Mac-specific; skip the chapter on how to compile the code, and use Xcode instead.

As for Objective-C: The Hillegass book is the most popular, but I didn't use it. (I have skimmed it, and it looks good.) I read Apple's document on the language, then jumped right in to writing small Cocoa apps. I read some of the guides, with mixed results. There is a Currency Converter tutorial, but it didn't help me at all, and doesn't quite reflect a modern Cocoa app. (Modern apps still use outlets and actions, but also Bindings, and a realistic Currency Converter would be almost entirely a couple of Bindings.)

I've started to read all available apple docs on this topic. A fast overview gave me a number of about 8.000 (eight thousand) DIN A4 PDF pages. About 10% of the content is almost equal for my feeling. After reading for 2 weeks now, I figured out that I would forget fast what I have been reading a week ago. Unless I start to do something with the knowledge, it's like a drain in the brain.

What are your learning strategies?

Here's what I did (I come from a Java/C++ background):

Starting off

  • Register to be an iPhone developer at (This is free)
  • Download the iPhone SDK (This contains, among other things the latest version of XCode and the SDK documentation -- both of which you'll be using very often when playing around with the SDK or when creating apps).
  • Get the Hillegass book. This book teaches the basic concepts of Cocoa very well. I've found it a good way to understand reference counting in Cocoa (retain, release, assign etc.)
  • Buy the Orange book on iPhone Programming. This is really good. (I'd bought Erica Sadun's book earlier, but that does not explain things from a beginner's perspective)
  • Try out the programs.

That should get you reasonably up to speed and developing basic applications. (I have not seen the Stanford video lectures yet, but I think that's a very good way to start too)

Getting better at it

  • To get a good understanding of Cocoa concepts, I've found the best resource to be the Apple Programming Guides. You should definitely read these. They have one on almost every topic, from NSStrings to Objective 2.0 properties, the memory model etc. You will find these in the XCode documentation. (If you're looking up a class reference etc. you will find the associated programming guides listed in the left sidebar)
  • Apple sample code: You'll find this again at You can reuse and/or adapt these.

You should be up and developing applications by now. If you're stuck or need advice, here are some additional resources:

What to do when you're stuck

  • The Cocoa-Dev mailing list (This is not Cocoa-touch specific per se, but I've got some very good answers from here)
  • The Apple discussion forums
  • IRC

(I'm not sure if the above resource list is good enough -- but others can correct me)

I have till now mainly concentrated on web programming thus far and now want to enter application programming space. I use a mac, and wanted to know what sort of compilers, IDEs etc people generally use for c++ dev.

extremely n00b One more thing immensely bothering me was the fact that c++ compilers generally output .exe which can't be used on macs. I need to understand basic OOP programming fundamentals and thought c++ would be the best choice. Please suggest something.

Compiling C++ on a certain operating system (OS) will create an executable file for that OS. You are not limited to only a .exe binary file.

The first step to start creating your first C++ application is to install Xcode. This development program is not installed by default with Mac OS X. You must insert one of the DVDs that came with your computer and install it. After, start Xcode and click on File and then New Project. Once that is done, select Command Line Tool and make sure that C++ stdc++ is the selected type. Before I forget to write this, Xcode's compiler for C++ is gcc. If you need some help to start off you always visits some sites or buy (or rent) some books.

One thing to note is that Apple's main programming language is Objective-C which is different from C/C++. While both of these languages have common features, it might be easier to start with Objective-C. It is possible to do some OOP with Objective-C and it will be easier with it. On the other hand, it is possible to do more complex OOP with C++ than with Objective-C.

If you ever wish to learn the basics of the Cocoa Framework (which is a set of libraries and tools to help you create a window), I suggest you learn how to program (some Objective-C or C++ could be nice) and buy the book Cocoa Programming for Mac OS X from Aaron Hillegass.

I have developed in C++ many years ago, but these days I am primarily a Java software engineer. Given I own an iPhone, am ready to spring for a MacBook next month, and am generally interested in getting started with Mac OS developmentmt (using Objective C), I thought I would just put this question out there: What Next?

More specifically, what books should I pick up, and are there any web resources that some folks could point me to? Some books that I am planning to purchase:

Anyone familiar with these titles? Finally, I would be very interested in a summary of what I should be prepared to expect, once I embark on this journey. As someone that develops in Java using IntelliJ IDEA, what are some key differences I will notice as I move over to writing ObjectiveC code in Xcode? What's the differences between Mac OS desktop development and iPhone development? Being used to Java garbage collection, what should I know about ObjectiveC garbage collection / memory management. Any other language specific issues that anyone would like to point out? How about building UIs? Is it closer to Swing, building Visual C++ resource files that code interacts with, or is it more like some of the borland IDEs that will generate code for guis?

Having purchased both of the books in your question, I recommend Cocoa Programming for Mac OS X as a quick way to learn the language and the Cocoa framework, and is probably the fastest way to start producing real applications in Cocoa. I highly recommend it. Programming in Objective-C 2.0 is a great reference book, but if you already know C, there's no much it's going to teach you that you can't pick up from the other book. However, if you ever need to a list of all the reserved keywords in Objective-C, that's the book to go to.

All of the user interface can be generated progmatically, but you'll find it much easier to use Interface Builder, which comes with XCode, to lay out the user interface. You'll end up with a lot less code. With bindings, you can even eliminate code which isn't directly related to laying out the interface. The details are in the Cocoa Programming for Mac OS X book.

The one big thing I miss from Java is the collection API. In Cocoa, you just get NSSet, NSArray, and NSDictionary, and there's no analog to the Comparable interface. These classes are also immutable, but have mutable versions such as NSMutableArray.

I actually haven't played with the Garbage Collection in Objective-C 2.0. In previous versions of Objective-C, memory management was handled by the retain, release, and autorelease methods. Objects were created with a retain count of 1. Retaining incremented that count, releasing decremented it, and autoreleasing objects is a little more complicated. Again, the Cocoa Programming book explains it well. Garbage collection is an option, and if it's turned on, the retain, release and autorelease methods do nothing. However, if you are writing a library or framework to be used by others, you should program it as if garbage collection is turned off. That way applications can use it whether or not they have garbage collection turned on.

As for Web resources, is a great site with beginner tutorials. The CocoaDev Wiki at contains detailed information on a lot of topics, and you can usually find some useful information and people on the cocoa-dev mailing list

iPhone development is a little different, and the details are restricted by an NDA. However, if you get approved by Apple to get access to the iPhone developer center, Apple has provided some great video overviews of the differences, which point you to the documentation you need to make the jump from Mac OS X to iPhone OS X programming.

I'm trying to keep things organized and create hierarchy of views for my app. So for instance I want to create a custom view to display some text, another custom view to display progress and then use all those views in the main view created with View-Based Application template.

I know how to create it programmatically - you create UIView subclass, implement drawRect method, place an empty UIView in Interface Builder and chance it's Class to my custom class. My problem is that I want to create those custom view's in Interface Builder instead programmatically.

So far I've created UIViewController controller with XIB file and in viewDidLoad method of view controller from the template I create that custom view controller instance and add it's view as a subview of that empty UIView added in Interface Builder (the same you would change Class in programmatic approach).

It works, but it's more of a hack for me and it's hard for me to believe that there isn't a better method where I could add those custom views in interface builder without having to implement viewDidLoad method and create controllers and add their views inside of that method.

For this to work, you have to create a plug-in for Interface Builder that uses your custom control's class. As soon as you create and install your plug-in, you will be able to add by drag and drop, instances of your view onto another window or view in Interface Builder. To learn about creating IB Plugins, see the Interface Builder Plug-In Programming Guide and the chapter on creating your own IB Palette controls from Aaron Hillegass's book, Cocoa Programming for Mac OS X.

Here is the link to the original author of the accepted answer to a similar question.

As Apple announces the Mac App Store, I'm going to learn Mac programming. I am typically one of those who read the Beginning iPhone 3 Development book before the Cocoa Programming for Mac OS X book. The reason I bought a MacBook was due to the fact that Xcode runs only on OS X. So, what's your tips for an existing iOS programmer who is also a Mac OS newbie? Thanks!

  • one tip for one answer please (as community wiki)

Highly recommend Cocoa Programming for Mac OSX by Aaron Hillegass .
This is a great starting point,as you are already an iOS programmer,it wouldn't be tough.

I just recently got my first mac. I do lots of programming on windows but now I want to get into Mac development. What are some languages i should know or tools i should use to get started with mac development?

I second hunterjrj's suggestion of Aaron Hillegass's book.

Another book that I'm reading at the moment which is a good tour of Xcode 3 is Fritz Anderson's Xcode 3 Unleashed.

Apple's development website also has lots of programming guides and video. Sign up at If you have an account already (or iTunes) it is easy to extend that to a developer membership. Note that you don't get all the developer info unless you pay for a full ADC membership. But all the API docs and programming guides are available without paying.

Cocoa(R) Programming for Mac(R) OS X (3rd Edition) by Aaron Hillegass:

enter image description here

Fantastic book and the author has alot of credibility - Apple brought him in to train their developers on Cocoa.

As a programmer, I've been pretty much stuck in the Windows world. I invested a lot of time and effort learning MFC, ATL and, recently, .NET (mostly WinForms, I'm not interested in Web development for now). Since I don't have Parallels (and won't buy any software or hardware in the following months), I can't afford to run my old Windows apps now, so I would like to port them to the Mac.

My main questions are:

  1. I've read there are two main APIs, Carbon and Cocoa. Which one would you suggest me to learn first? (I don't know Objective-C, but I'm not against learning it.)
  2. What are the main development tools (IDEs, debuggers, etc.) for the Mac?
  3. Are there any frameworks or RAD tools that help with with window creation (I'd prefer a MFC-like approach to a VB-like drag-and-drop editor).
  4. Could my current skill set help me in learning to program for the Mac, or do I have to start basically from zero?

To answer your questions:

  1. Cocoa. And learn Objective-C. There are several questions here on SO about this. You could also try RealBasic.
  2. Xcode, free with Mac OS X.
  3. It's in Xcode. Xcode has a UI builder.
  4. It will help, but the Mac is a different animal. I suggest Cocoa Programming for Mac OS X by Aaron Hillegass.

I come from a similar background (Windows, ASP.NET, C#) and I found the Mac to be very fun as a platform for software development. The iPhone is very interesting too. I'd suggest you browse through past questions here on SO for more info about Mac development. There have been some great questions and answers.

I am planning to learn how to use XCode and start developing on the apple platform. I have a visual studio background, and I can use unix (not a hardcore scripter but I know more than the average)

If anyone could point me to a good tutorial in apple especially a getting started in XCode, your first app in XCode, plus anything you think would be good for me to know, can you pass it on?

If you haven't already check to make sure your build environment is good. My experience with OSX on a PC has been that a lot of stuff, like XCode and some dev libraries aren't installed.

Once you validated your build environment spend sometime getting use to XCode and Interface builder. Understand how the two work together. XCode and Visual Studio are quite different, but once you get the hang of XCode and Interface builder you'll dig it.

Then get this book from Aaron Hillegass. This is a great resource all Cocoa programmers should have. You may also want to grab one of the iPhone development cookbooks for some good examples and patterns on how to build your apps.

When you first start to develop apps start with smaller projects at first, stick with a single framework for these little projects. Once you master or semi master the framework pick another one and add onto your knowledge base.

Lastly, build yourself a nice application, sell it, make some money and buy yourself a Mac ;)

I'd like to learn how to write application for Mac OS X.

Like how to use XCode properly, Cocoa syntaxes and examples, etc.

I'm already a web developer using ruby, php, mysql, rails, etc.

I looked through google quite some times but never found something palpable to learn from.

But I really want to make my own application, for fun and maybe business later.

Thanks a whole bunch for your tips!

You should start by learning Objective-C. Programming in Objective-C is an excellencent introduction to the language

If you're looking for a free resource this is an excellent web-site

Only after you have a solid understanding of the language would I worry about the different frameworks available.

Aaron Hillegass's book "Cocoa Programming for Mac OS X" is certainly up there. It would also be well worth your time to learn the C language well.

I'm learning iphone dev, and also want a solid handle at desktop development for the mac.

What do you guys recommend?

Language wise, is objective-c all I need?

Is desktop development locked down at all, or are you free to do anything once it is installed?

Does each app run in its own space as to not effect other desktop apps?

  1. Cocoa Programming for Mac OS X is generally regarded as "the bible" of desktop Cocoa development.
  2. Objective-C is all you need, for the most part. Very rarely will you need a more domain-specific language. There are more options (MacRuby, PyObjC, Java, REALbasic, etc), but it's extremely common to do everything in Objective-C.
  3. Any "lockdown" on the desktop would be defined by the app store approval process and the permissions you can acquire from the user.
  4. Apps are not sandboxed on the Mac.

I've been using MacBook Pro for a few months at home, and I was wondering if there's a good book or guide that can help me be a better programmer on Mac. Maybe Mac-equivalent of Beginning Linux Programming. Note I am not looking for resource on how to program Mac application, instead I am looking for more general guide of using Mac for general development environment.

As a background, I am a Windows programmer by day. I've also done some Linux and BSD over the years, esp in school, like socket programming, graphics, make install type stuff. At home, I'll be doing Java, Scala, PHP, etc. on Mac.

So far, I've been using Eclipse, QuickSilver, and TextMate. VMWare Fusion, XCode and NetBeans are set up, but I don't use them. A DVI KVM switch is hooked up to real keyboard, trackball, and monitor. Recently stayed up till late fighting with MacPorts, and figured out I needed x86_64. The most struggle I had was configuring PHP. I don't know why they don't ship with MySQL and GD library. I eventually figured it out Googling around, and built the extensions from source. I have a feeling that I didn't get the memo and didn't read some basic guide on how to become a programmer on Mac, like how the whole architecture works. How can a Windows programmer be sufficiently productive on Mac OS X?

Related: Setting up a Mac for programmers

Edit: The specific type of application I want to develop doesn't really matter in my opinion. It could be Java, Scala, PHP as I mentioned or Cocoa, C++, or whatever.

What I am looking for is specific book, resource, advice on how to be more effective programmer on Mac, preferably something beyond "install XYZ".

You seem to want an overview of how Mac OS X works at a system level, more than recomenations about tools and so forth. If that's the case, I'd start with the (very basic) Mac OS X System Architecture Guide from Apple, then move on to Getting Started with Mac OS X, which should give you enough of an overview to get started.

It's not clear from your question what you intend to actually make with your programming time, but if you decide to persue Cocoa/OS X development, I recommend Cocoa Programming for Mac OS X by Aaron Hillegass.

Can anyone guide me how to write a Mac application right from scratch, I'm new to Mac concepts, though I have worked on iPad, iPhone applications. Even a tutorial would work...

Thanks in advance

Cocoa Programming for Mac OS X by Hillegass is a good book for learning about Mac GUI programming (Objective C and Cocoa).

I am an experienced C++, C# programmer on Windows platform and would like to learn Objective-C to try out developing on the Mac and iPhone.

What books do you recommend me to start out with?


I'm reading Learn Objective-C on the Mac and find it good.

Cocoa Programming for Mac OS X by Aaron Hillegass is great for learning Mac programming.

To learn objective-c specifically -- not Cocoa or Cocoa touch -- I have and like:

Programming in Objective-C 2.0 (2nd Edition)

Programming in Objective-C 2.0 cover

The reason that I like this book is because it doesn't assume extensive knowledge of C. Of course, knowing C -- or any C like programming language will help. But this presents Objective-C as Objective-C the programming language and not Objective-C the extension to C. I think this is important because C and Objective-C have different ideology. Yes, they share attributes but programming in C is a different experience from programming in Objective-C. Your book should reflect that. :-)

This shouldn't be this confusing. I have a custom UIView with a bunch on controls on it. UILabels, buttons, etc. I've created this Nib using Interface Builder. I want to be able to position this custom uiview on another UIView using the interface builder.

How do I link my UIView custom class, to the nib? initWithCoder gets called, but I want this class to get loaded from the nib.


For this to work, you have to create a plug-in for Interface Builder that uses your custom control's class. As soon as you create and install your plug-in, you will be able to add by drag and drop, instances of your view onto another window or view in Interface Builder. To learn about creating IB Plugins, see the Interface Builder Plug-In Programming Guide and the chapter on creating your own IB Palette controls from Aaron Hillegass's book, Cocoa Programming for Mac OS X.

Here is the link to the original author of the accepted answer to a similar question.

Actually I don't care too much about Mac OS X development. I want to do only iPod Touch and iPhone development. But anyways, I started learning Cocoa and Objective-C. But it seems like there are many differences between Cocoa and Cocoa Touch, so I am wondering if I am actually wasting my time. Should I just jump directly into iPhone topics?

I've taught Mac developers and iPhone developers, and my experience is that it's generally best to learn Mac first, particularly because you can get a solid grounding in Cocoa using Cocoa Programming for Mac OS X, which is still the best book on learning the Cocoa patterns around. So far I haven't found a good iPhone book that teaches the key issues you need to know, and that differentiate Cocoa/Touch programming from Java, .NET and other systems. I've written a couple of articles recently that may be helpful as you think about this:

iPhone Course Syllabus

Review of iPhone Developer’s Cookbook

I think you could go either Cocoa-Cocoa Touch or Cocoa Touch-Cocoa and still have a good grasp on what it takes to program for either platform. I tried Cocoa development on my Mac a few years ago and was pretty confused. I finally decided to take up iPhone programming, and picked up Beginning iPhone Development: Exploring the iPhone SDK, worked through that book over a few weeks, and I understand things much, much better now. Really, all it takes is a good explanation of Mac programming. I'm fairly confident I could pick up regular Cocoa programming with far less effort now. Had I started with regular Cocoa programming, I'm fairly confident I would have been able to pick up iPhone programming fairly easily. There are differences, but there are a lot of (very cool) similarities between the two platforms.

PS, I highly, highly recommend that book if you're really interested in iPhone development. It was worth every penny.

Normally I would agree with the other answers here: directly learn the topic you're interested in. But in the case of Cocoa/Cocoa Touch, you'd be better off reading Cocoa Programming for Mac OS X, 3rd ed. by Aaron Hillegass. It's just that damn good!

I am eventually wanting to program in Objective-C to write programs for OS X and possibly the iPhone. I do not have any direct experience with C and I come from a web programming background. I am much more familiar with java syntax than C and Objective C.

I am just looking for suggestions on how to get started. It looks like I need to just start with C (I do not yet have a Mac computer powerful enough for programming, so it would be nice to start with C on the Windows platform anyway (information about programming environments would be helpful too, I am used to eclipse)). I am just looking for book recommendations, online tutorials or any other pointers to keep in mind. Keep in mind though that my end goal is to work with Objective-C, so is there anything I need to keep in mind when learning C, anything to watch out for, etc. Thanks for any input.

Update: The reason I am thinking I need to learn C first is that most of the tutorials that I have come across so far for Objective-C assume you already understand C syntax, which I do not fully. Are there better tutorials out there for me?

If you know java, obj-c will be easy for you (java was influenced a lot by obj-c.) Apple has great documentation, you can start here. I don't think you need to learn C before learning obj-c (sorry Joel).

You can use obj-c on windows if you get gcc. Also check out cocotron:

The Cocotron is an open source project which aims to implement a cross-platform Objective-C API similar to that described by Apple Inc.'s Cocoa documentation. This includes the AppKit, Foundation, Objective-C runtime and support APIs such as CoreGraphics and CoreFoundation.

With all the buzz about iPhone development, there are now dozens of obj-c books. Not sure how good they are, but a classic that I would suggest is Cocoa Programming from Mac OSX by Aaron Hillegass.

I'm a Windows (native, not .NET) programmer and I'd like to port an application to the Mac.

Actually, I believe it will be more of a rewrite, as the original depends on many activex controls.

As I have never used a Mac in my entire life, I'll need some guidance. O:-)

a) What book(s) would you recommend to make the move from Win32 to Mac OS?
b) Is there anything similar to Delphi (RAD) for the Mac?
c) Can anyone recommend (or not) Lispworks (
d) Is there anything similar to the Windows market of 3rd party COM components (so I don't have to write everything)?
e) Anything else I should be aware of the Mac market?
f) Oh, BTW, what Mac should I buy? O:-) (must be a laptop)

Thanks in advance

I've taught Cocoa programming to several Windows-experienced programmers. You may find a previous post on the subject useful.

Cocoa is a very different way of thinking then MFC and its kin. You will do much, much better if you take the time to learn how Cocoa approaches things and adapt to its mindset rather than trying to find the quickest way to implement your current way of thinking in ObjC. It is possible to write MFC-style code for Mac, but you will always be fighting the framework if you do. I've seen a lot of Windows developers struggle with this.

The best book to learn Cocoa is Cocoa Programming for Mac OS X. Assuming you are a C++ developer with a solid OOP background, this is the book to start with. If you have limited Object Oriented background, then start with Programming Objective-C 2.0.

You would be amazed how fast Objective-C can be to code once you understand the patterns. It really can be stunning compared to C++ in my experience. There are more RAD-like systems like REALbasic, and you can develop Cocoa apps in Ruby now which can be a bit quicker. But there really is no substitute in the Mac market for ObjC. It's hard to make an app that works like a Mac app without using the Mac frameworks, and Mac users tend to be much fussier about such things than Windows users.

I have no background in LispWorks, but LISP seems a terrible language for developing the kind of rich UIs that Mac apps are known for. I like LISP (quite a lot actually), but Functional Programming's "no side effects" philosophy seems at odds with most rich UI goals (especially as the Mac UI becomes more and more animation-centric). If anything, Mac programming is moving towards Declarative rather than Functional programming (Core Animation and Grand Central Dispatch have a lot of Declarative concepts creeping in).

There is not as large a third-party component market as there is for Windows. Some of this is because Cocoa already provides such a rich set of components, which MFC does not, and because well-behaved Mac apps are expected to use those components so that you work like all other Mac apps. There is definitely little market for commercial components in the vein of RadControls for .NET (very nice toolkit, that one). But there are quite a few nice free components out there with flexible licenses (generally MIT-based). A few of my favorites:

As I mentioned before, Mac users are picky about their UI. Much, much more so than Windows users. They expect things to be polished, and they expect things to integrate with all the little things that make Macs nice. That means drag-and-drop, Spotlight, services, Applescript, Expose, QuickLook, integrated spelling check, etc. etc. It's very hard to do all these things right if you don't use the built-in frameworks. That's why I recommend new Mac developers start at the beginning and learn the frameworks.

For a Mac, if you have a bunch of hardware lying around (like keyboards and monitors), then a Mac Mini is a nice cheap box. iMacs are great if you want an all-in-one, and any MacBook is appropriate if you like portability. There is no Mac on the market today that is not a perfectly fine development box. Obviously if you do a lot of work, an 8-core Mac Pro makes compiling much faster, but I've done a lot of professional development on a 13" MacBook. If you want to get in as cheaply as possible, look for refurbished or used (I love my refurbished Mac Mini). Any Intel-based Mac is going to be fine for development, at least while you're getting started.

I am new to Objective-C, so this might be a dumb question.

I cannot help but see the similarities between ObjC and Microsoft's COM with respect to memory management (AddRef/Release vs retain/release). In a COM environment, it's more or less imposed on you to always AddRef (retain) an object before returning it to the caller. From what I've seen so far (I'm a third through Cocoa® Programming for Mac® OS X (3rd Edition)), the memory management part is somewhat fuzzy.

Assuming there is no GC, what is the idiomatic way to return an object?

Read Memory Management Programming Guide about autorelease pools.

In Objective-C, by convention, objects should be returned autoreleased (unless the method returning the object has a name that begins with “alloc”, “new”, “copy”, or “mutableCopy”). Autoreleased objects are tracked by Objective-C in a pool and automatically handled, which means you don't need to care about sending a final release to them. This greatly simplifies reference counting compared to COM, and this is why you're not seeing any release calls on returned objects most of the time. In contrast, the same convention specifies that all objects returned by a method whose name begins with alloc, new, copy, or mutableCopy, are the responsibility of the method caller. You have to manually call release on these objects or your program will have memory leaks.

I have a question I really want answered. I have been playing around with some Objective-C for a few weeks, and I have been reading in the book Cocoa Programming for Mac OS X until Chapter 7.

In chapter 5 and 6, there is a challenge you should do, especially chapter 5 where he write:

This exercise is an important challenge that you should do before moving on. Although it is easy to follow my instructions, you will eventually want to create your own applications. Here is where you can start to develop some independence.

But I have not been successful on those challenges: tbh, I have no idea how to do them... It does not even help to look back the previous chapters and steal the code, I have no idea how to make it work and what I should be typing.

So my question is: how long did it take you to probably know Objective-C? For those who have read the book: where you able to do the challenges?

I really want to learn Objective-C program for the iPhone, but now that I don't even know how to do the challenges, I doubt it's possible for me to learn it... Is there still hope?

It should also be said that besides the challenges, much of the code he writes makes no sense to me. I am not sure why he writes it and what it does 100%. Please help me on this one!

Thank you in advance

It sounds to me like all you need is a conceptual foundation.

Like you, I came from C, so I've been there.

Start here:

Then, learn Objective-C (the actual language) and Cocoa or Cocoa Touch:

Don't worry about how long it'll take. Take your time. Work as fast or as slowly as you want.

I really want to learn Objective-C program for the iPhone, but now that I don't even know how to do the challenges, I doubt it's possible for me to learn it... Is there still hope?

It should also be said that besides the challenges, much of the code he writes makes no sense to me. I am not sure why he writes it and what it does 100%.

If you're trying to implement them on the iPhone, that may be the problem: The book is Cocoa Programming for Mac OS X, and Cocoa and Cocoa Touch have some big differences between their application frameworks (AppKit in Cocoa, UIKit in Cocoa Touch). I would say either learn Cocoa (and implement the examples as Mac apps) first, since that's the book you have, or abandon that book and switch to one more iPhone-appropriate.

The Hillegass book gets a lot of recommendations, so if you find a different one that's better for iOS programmers who want to skip the Mac, don't be afraid to recommend it.

ETA: Also, if you don't want to program the Mac at all, your local library would probably love a current copy of the Hillegass book.

I'm looking for a tutorial/guide on GUI programming in c++ for Mac OSX.

I've made a small library and would like to make a simple graphic interface for it, since I would like to port my code someday I would like to do the programming in c++.

I know about Qt, but would like to know how apples does it. As I understand it there are two frameworks for doing gui programming on macosx, Cocoa and Carbon, I have no preference, but would just like to play around with some buttons and other widgets.

if anyone knows of such a tutorial this would be nice.

To start with, you beg, borrow or steal a copy of "Cocoa Programming" by Aaron Hillegass.

I'm primarily a designer, with a fairly high level of understanding of CSS and HTML. I have an idea for a very simple iPhone app, largely involving a timer, an animated graphic, and some sound. If I get more advanced there could be some simple customization settings

I have no understanding of Objective C, or C of any kind for that matter. (The closest I got was a Pascal course 20 years ago.) Aside from befriending a developer with motivation to help me out, what would be the simplest, most likely method of learning the minimum I need to know to create my own iPhone App?

If you're really serious about it and are willing to put in some time to actually learn to program in Cocoa, the way I would do it would be a combination of reading all the stuff Apple has to offer along with a couple good books both for reference and more conceptual big picture/getting into the Cocoa mindset stuff.

If you just want to try to hack something together that works than you'll probably do best with a combination of Apple's sample code and lots of questions on various forums when you get stuck.

The books I would recommend would be Programming in Objective-C, by Stephen Kochan and Cocoa Programming for Mac OS X, by Aaron Hillegass. The former is a good introduction to the Objective-C language itself, and the latter is pretty much the Cocoa book. It's not an iPhone specific book, but pretty much everything in it (especially the concepts and design patterns) still apply. Keep in mind you wont have access to the garbage collector on the iPhone. You should also be sure to read through Apple's own Introduction to The Objective-C 2.0 Programming Language.

For actual code to look over and adapt to your own needs, it's hard to find anything better than Apple's own iPhone sample code library.

You might also try these two forums for any SDK questions you might have, as well as of course Stack Overflow for the more general stuff that doesn't fall under the NDA.

with GUI apps I mean not just a Unix command line application, but the whole .app bundle and a full Cocoa or Carbon application.

PS: I wasn't totally accurate with GUI application.
I meant an application with a window and a menu, as opposed to a Unix command line application.
Actually I got to a tutorial about programming with SDL and OpenGL on MacOSX and it even has XCode templates which come with the ObjC needed to set up the menus, and it's pretty much what I was looking for.

Is C++ a requirement? Most of GUI programming for Mac is done with Objective-C or C. The book of choice is Aaron Hillegas' Cocoa Programming for Mac OS X. It's an outstanding book that will let you jump in right away.

Anybody know any good tut's for iPhone development? I have written a game in AS3 and have excellent knowledge of PHP/OOP etc but I cannot get my head around the iPhone SDK or the objective C syntax and structure.

I'm in similar situation and these are the steps I'm following and the books I bought:

  1. Learn Objective C: "Programming in Objective C" by Stephen Kochan
  2. Learn Cocoa & AppKit: "Cocoa Programming for MacOS X"
  3. Learn Cocoa Touch (specific framework for iPHone): "iPhone for Programmers"

Good luck and have fun.

Check out the last lines before [return cell]..After the images are being loaded the scrolling speed is seems the scroll gets stuck

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *MyIdentifier = @"MyIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];

    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    NSString *itemDescription=[[stories objectAtIndex: storyIndex]

    CGRect aframe = CGRectMake(80, 30, 250, 40); 
    textLabel = [[UILabel alloc] initWithFrame:aframe];
        textLabel.font = [UIFont boldSystemFontOfSize:14];
    textLabel.textColor = [UIColor darkTextColor];
    textLabel.backgroundColor = [UIColor whiteColor];
    [cell.contentView addSubview:textLabel];

    CGRect frame = CGRectMake(0, 0, 70,80);
    UIImageView *TopImageView = [[UIImageView alloc] init];
    [cell.contentView addSubview:TopImageView];

    m_strImage = [m_imglinkArray objectAtIndex:storyIndex]; 

    TopImage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:m_strImage]]];

    return cell;

Could you guys help me to increase the speed of the scroll?



nessence has a lot of good information. A few more thoughts:

You're leaking like crazy here. Every cell you create, you leak 2 UILabels, a UIImageView and a UIImage.

As noted before, not only are you leaking these, they're accumulating in your view because you're sticking one on top of the other with addSubview:.

Reaching out to the network during a cell draw is incredibly slow and is blocking your UI. If these URLs are local, then you can use UIImage's +imageWithContentsOfFile, if not, you need to load this in the background.

I don't think you need a thread here. NSURLConnection is an excellent way to load data in the background without incurring the overhead of threading.

nessence is completely correct that you need a model class for Story.

Your basic approach to reusable cell configuration is incorrect. You don't fetch a reusable cell and then add subviews to it. All your subviews should be added in the if() block to create the cell. Then, in each pass, you just change the values of things. I've rewritten some of your code below to demonstrate. This is still not correct code, because it is reaching out to the network during a cell draw, and this may be too many elements to be in a subview-cell (rather than a custom cell), but it's closer to the right idea. I don't even know if this compiles; I just typed it here.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *MyIdentifier = @"MyIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    if (cell == nil) {
        // Here we do all our cell creation
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];

        // Make the label
        CGRect aframe = CGRectMake(80, 30, 250, 40);
        UILabel *textLabel = [[[UILabel alloc] initWithFrame:aframe] autorelease]; // Note the -autorelease so we don't leak

        textLabel.font = [UIFont boldSystemFontOfSize:14];
        textLabel.textColor = [UIColor darkTextColor];
        textLabel.backgroundColor = [UIColor whiteColor];
        textLabel.tag = DescriptionTag; // A tag so we can find it later (you'll need a constant for this)
        [cell.contentView addSubview:textLabel];

        // And the second label
        aframe = CGRectMake(80, 30, 250, 40);
        textLabel = [[[UILabel alloc] initWithFrame:aframe] autorelease];
        textLabel.font = [UIFont boldSystemFontOfSize:14];
        textLabel.textColor = [UIColor darkTextColor];
        textLabel.backgroundColor = [UIColor whiteColor];
        textLabel.tag = TitleTag;
        [cell.contentView addSubview:textLabel];

        // The image view
        CGRect frame = CGRectMake(0, 0, 70,80);
        UIImageView *topImageView = [[[UIImageView alloc] init] autorelease];
        topImageView.frame = frame;
        topImageView.tag = TopImageTag;
        [cell.contentView addSubview:topImageView];

    // all the above was cell creation; we do that as seldom as possible.
    // Now we do cell configuration. We want this to be fast.

    UILabel *descriptionLabel = (UILabel*)[cell.contentView viewWithTag:DescriptionTag];
    descriptionLabel.text = itemDescription;

    UILabel *titleLabel = (UILabel*)[cell.contentView viewWithTag:TitleTag];
    titleLabel.text =[[stories objectAtIndex:indexPath.row] objectForKey:@"title"];

    NSString *imageURLString = [m_imglinkArray objectAtIndex:storyIndex]; // You should have a model class called Story, not two arrays.
    UIImage *image = [[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageURLString]]] autorelease]; // This is still way too slow if it's a remote URL 
    UIImageView *imageView = (UIImageView*)[cell.contentView viewWithTag:TopImageTag];
    imageView.image = image;    

    return cell;

I recommend you spend some quality time studying TableViewSuite, Practical Memory Management, and Coding Guidelines for Cocoa. Some time studying the basics of Cocoa would be useful as well, because the coding style here indicates that you may not have a solid foundation. Though it's a Mac book, I still recommend Cocoa Programming for Mac OS X. If you're interested in using this to learn iPhone, I've put together a syllabus that might help. I haven't reviewed it yet, but Stanford's online CS193P course looks promising.

Don't shoot me, I know this must have been asked a thousand times...

I am not comfortable with the lack of good documentation on Objective-C memory. I understand alloc, dealloc, retain, release and all that but there is some confusion left in my head.

Is it just lazy programming or does Objective-C do some 'behind the scenes' automagic activity in regard to allocating memory?

Coming from a C background (centuries ago), I know that pointers are just pointers... you also have to reserve space for what the pointer points to or you will start stomping on your own program and other variables.

The code examples I find (and that are in the books I read - all of which are sadly out of date with the current version of XCode and Interface Builder) never seem to allocate storage space for some objects such as NSString. They declare a pointer (eg. NSString *aString;) then start assigning text to the string. No allocation of memory for the string is every invoked!?!? So are all these examples just lazy code looking for a place to crash?

Also, books talk about declaring 'pool' memory and that it is automagically inserted into your code. When I create projects, classes and objects, no such code is to be found anywhere. Has Apple done away with this automatic insertion or is it something that happens during compile time?

Is there a penultimate reference book or website that will explain all this once and for all?

I think the best reference available for understanding memory management in the Objective-C language is the The Objective-C 2.0 Programming Language available as a PDF from Apple at the following URL:

Chapter 3 Allocating and Initializing Objects speaks to memory management.

A less detailed but more concise discussion of memory management in the Objective-C language can be found at Very simple rules for memory management in Cocoa found in the URL below:

Your specific question concerning NSString allocation rules are covered in that article under the title Retention Count rules.

"Objects created using convenience constructors (e.g. NSString's stringWithString) are considered autoreleased."

Another good book for understanding Cocoa programming in general that has many examples and explanations is Cocoa Programming for Mac OS X (3rd Edition) available from Amazon here:

The author Aaron Hillegass has been programming in Objective-C since the Next days and now teaches Cocoa programming for a living. I own the book, but I don't have it on me so I can't tell you the specific chapter to look at right now. However, I can assure you that it is a good book.

I hope the above references are helpful for your understanding.

I am an iPhone developer and know that framework well. With the Mac App store on the verge, I'l like to learn more about Mac development. Are there any good guides/tutorial/etc. to help with the transition? I have looked around and not found much. Thanks for the help!

You basically need to learn the difference between UIKit and AppKit. (Foundation and Core Foundation are the same on both platforms.) They are subtly different; there are more frameworks which comes with the OS X than with the iOS; a framework with the same name might have more functionality on OS X, etc.

But that's basically it, if you distribute the app through the Mac App Store, because you don't have to learn how to package things by yourself.

The best book on Cocoa programming for Mac is this, but it might be too elementary for an experienced iOS programmer. But it's still a good book.

I guess we'll see a flood of books for people like you, showing the way of Mac development to competent iPhone programmers; but it hasn't happened yet. Maybe you might write one, from your own experience :)

I'm a C++ and Javascript developer who is learning objective-c to be a hobbyist cocoa/objective-c programmer for mainly Mac OSX desktop applications. I'm pretty green when it comes to objective-c/cocoa, and I was wondering how I can add a button to my main view and bind a custom handler to that button when it's clicked? What's the best way to do this? I've done this many times with wxWidgets, but this is my first cocoa application to help me learn and get my feet wet.

I would also appreciate any book suggestions or learning resources that you could point me to.


Alex, I would highly recommend you check out some books before you dive into Objective-C. Coming from C++ and Javascript, you're going to have to better adapt your mindset to what you are going to learn, and if you don't prepare yourself, you're going to be very, very confused. As quixoto said, definitely take a look at Aaron Hillegass' Cocoa Programming for Mac OS X, as it will walk you through the process of creating applications and using Xcode and Interface Builder. Before that, however, I would highly recommend you check out Stephen Kochan's Programming in Objective-C 2.0, to get a primer on the language and its concepts (although C++ and Objective-C are supersets of C, they are both quite different).

I'm a PHP developer, and I use the MVC pattern, and object oriented code. I really want to write applications for the iPhone, but to do that I need to know Cocoa, but to do that I need to know Objective-C 2.0, but to do that I need to know C, and to do that I need to know about compiled languages (versus interpreted).

Where should I begin? Do I really need to begin with plan old "C", as Joel would recommend?

Caveat: I like to produce working widgets, not elegant theories.

Get Cocoa Programming For Mac OS X by Aaron Hillegass. This should get you on your way to Cocoa programming. You can look up C-related programming as things come up.

K&R C Programming Language is the definitive reference that is still applicable today to C programming.

Get the Cocoa book, work though it and if you encounter any snags, just ask your C questions here :)

Yes, you're really best off learning C and then Objective-C. There are some resources that will get you over the C and Objective-C language learning curve:

And there are some resources that will get you over the framework learning curve:

Despite what Jeff might say, learning C is important for professional software developers for just this reason. It's sort of a baseline low-level lingua franca that other innovation happens atop. The reason Jeff has been able to get away with not learning C is not because you don't need to know C, but because he learned Pascal which is in many ways isomorphic to C. (It has all the same concepts, including pointers and manual memory management.)

No need to start with plain C. Start with an excellent book instead: Cocoa Programming for Mac OS X.

I'm a windows programmer with lots of experience building apps in .net, and I'm currently trying to get my hands dirty doing some hacking on the mac. I'm interested in using mono and specifically using monomac to ease the transition by staying in the warm, cosy and familiar .net environment. However, I'm having a really hard time wrapping my head around all the mac-specific apis, libraries and tools, such as interface builder, xibs, file's owner, first responder, *kit, and all the other-worldly mac weirdness. I've been on one platform for too long and my brain is locked into a particular view. To anyone who has blazed this path before me, could you recommend any books to read to get me up to speed? Ideally I'd love to read a detailed comparison of the windows vs mac apis, tools and libraries, to help me with the translation. Many thanks in advance!

I'm a Windows convert as well (from MFC/C++, not .NET) and I highly recommend Cocoa Programming for Mac OS X.

I'm new to Objective-C.

If I wrote this method declaration in .h


and this implementation in .m

    NSLog(@"This is myMethod");

How can I call it in my class' viewDidLoad method?

Thank you.

Assuming that you're calling myMethod on the same class as what implements viewDidLoad:

- (void)viewDidLoad {
    //...other code
    [self myMethod];
    //...other code

If you are having trouble with basic Objective-C though, I'd strongly suggest to either get a decent book on Objective-C, such as:

…or at least read a good beginners tutorial, such as:

There are quite a few more helpful beginners tutorials by Scott Stevenson here:

I need some info about how to assign, retain objects.

For example - if we have two viewcontrollers and needed to pass an array data from viewcontrlr 1 to viewContrl 2, how can we send the object from view 1 to view 2 and release it in view 1 and retain it in view 2.

A simple = operator is just assigning the address which again points to view 1 object. What is the best way so we can release obj in view 1 and retain a new object in view 2 when passed from view 1.

Also, you may want to check out this article for info on retain count mechanisms in general. It's very similar to what's in Cocoa Programming for Mac OS X which IMO is one of the best intro books on Cocoa and Obj-C in general. I'm not sure how much experience you have with Obj-C/Cocoa but if you're looking for that kind of intro it's a great place to start.

I need to build an application which will run on OS X, polling for data, and displaying that data full-screen in a purty, graphical way - generally "identifier: value" text in some sort of tabular format, but possibly with spark-lines to display historical changes, and "animations" (nothing fancy, just fading text and similar) to show updates.

However, I've no idea where to get started. I've no experience with desktop application development or development on a mac.

Where/at what should I be looking for OS X development information which will get me quickly up-to-speed (coming from a web-dev background)?

For OS X development, and a really nice overview that will get you writing actual applications quickly, I'm not sure anything can match Aaron Hillegass' book, Cocoa Programming for Mac OS X.

It's considered by many to be the Bible of Cocoa programming, and it is example driven. You are writing applications that you can actually run throughout.

It is useful, although not as much so, for iPhone development, which you don't mention in your question, but you do in your tags.

i've been reading for a while a little bit of Objective C and Cocoa, and i have to say that although i am thrilled with the overall simplicity of Objective-C, I feel totaly lost regarding Cocoa and especially the MVC design pattern. The Cocoa books I've read, ask the reader to just complete a set of steps for a program to work, without doing much explanation about the mechanisms of the API. I am trying to understand the overall meaning of NSTableView, NSOutlineView, their datasources, their delegates, and what all these have to do with the various controller classes like NSArrayController and NSTreeController. So i have a couple of questions to ask:

  • How do these classes really interoperate ?
  • Is the datasource of an NSTableView an instance of an NSArrayController ?
  • Should a delegate and a datasource be the same class in a NSTableView or NSOutlineView ?
  • Leaving binding aside, do NSArrayController and NSTreeController have any other important advantage ?

Let's assume that there is a container (in C) with some sort of data (a C struct). We want to be able to show these data in an NSTableView (or NSOutlineView) and to exchange views at runtime, if the data structure is hierarchical. Should i create a class that has an NSArrayController (or NSTreeController) as instance, and wrap the functionality of the C container ?

Thank you and forgive me for my silly questions.

These are not silly questions. You're asking precisely the right questions, and have gone to the heart of how to learn Cocoa. Learn MVC first, and how Cocoa implements it, and the rest will be clear.

While slowly becoming dated, there is still no better book for learning Cocoa than Cocoa Programming for Mac OS X by Aaron Hillegass. I wrote up some more comments about this book last year if you're interested. And some more guides (mostly targeted at new iPhone developers) here and here.

To your specific question, rather than store the data in a C struct, store it in an Objective-C object (a model object, the "M" in MVC).

Then build a Controller class to be the datasource for the NSOutlineView (which is designed for hierarchical data). For the moment, avoid Cocoa classes that end in "Controller." These are related to bindings (and mostly used for Core Data). While very powerful, they're more than you want to dive into at the beginning (and even after years of Cocoa programming, I only use bindings for certain targeted problems; they can make your programs very hard to maintain if they're complicated). Your controller for now should be a subclass of NSObject. It will implement the NSOutlineViewDataSource methods. If you need a delegate, it is common and natural to make the same object be the datasource and delegate.

Possible Duplicate:
Getting Started With iPhone Development

I have been hired for iphone development in a digital arts group. I have previous experience in android/Java and C/C++. The project which I ll work is related to iphone game development. I have no previous experience in iphone dev. So now how would you ppl suggest me to start ? as I ll be working on iphone game dev in next few weeks.

As I wire up my first fairly complicated Cocoa-Touch view I feel like I'm inadvertently slipping back into old procedural patterns and finding it difficult to shake them off...Though fully aware of many of the Cocoa (OO) design patterns I'm afraid I may be subverting them.

As such this view in question is quickly becoming unmanageable and I'm wondering if I might be approaching it the wrong way?!? The view is managed by a subclass of UIViewController. The view itself contains ±10 subviews. Some of these subviews "slide" in and out and contain their own subviews (controls, imageviews, etc) that slide along with them.

Without getting into too much detail I've found that I'm executing most (if not all, including animation) of my management code w/in the touchesBegan/Moved/Ended methods of my root View Controller. And it's become a mess of managing, setting & checking boolean properties. if (editingMode & panelAVisible).... if (editingMode & panelBVisible)... or *if (viewFlipped) { for (MyCustomView view in someArrayOfSubviews)} etc, etc... granted the UI of this app requires most of these views (or their contents) to be touched and moved by the user to different parts of the screen.

The main problems I'm trying to solve seems to be along the lines of: if viewA is present then you 3 views go hide (animated)...or, If viewB is touched then all objects contained in viewC are negative... etc.

Any clever (or rudimentary) OO approach to handling this? Perhaps make the subviews that contain views act as their own mini view controllers? I haven't been able to find too many (any?) examples of that though...

As you suggested at the end of your question, I would recommend having a subcontroller whenever you need logic for a particular subview. The point of a controller object is to keep track of state of the view and to encapsulate all that view logic that you were describing. Interface actions, such as if the user can move to a different screen, can invoke save logic, can create a new document, should be in the controller for that particular view. This will help maintain a separation of concerns between the various controllers and cut your convoluted logic down at the top level.

While it doesn't pertain to iPhone programming specifically, the book Cocoa Programming for Mac OS X contains good examples (especially in the chapter about how to do preference windows) of using subcontrollers and subviews in your application.

I am currently an iPhone application developer. As an iPhone developer, I figured I could also create and sell Mac applications now that there is a Mac Application Store.

I have learned from Apple that - similar to what is required for the iPhone - I need to join their Mac Developer program for $99 in order to submit applications to the Mac Application Store.

My question is multi-part:

  • How similar is developing for the Mac to developing for the iPhone?
  • What resources are available for learning how to create Mac Applications?

You're in luck! They've got many of the same foundations (Cocoa, Foundation, Obj-C)! I made my biggest initial strides in mac programming reading Cocoa Programming for Mac OS by Aaron Hillegass.

I am not sure if StackOverflow is the right service to ask this question but I believe it worths to try.

I am an experienced PHP developer and now interested in building some iPhone apps. I have searched on Google for tutorials about objective-c but couldn't find a good one for beginners.

Do you have any suggestion, something like Objective-c for dummies? :)

Thanks again.

Programming in Objective C is a great book to start off with. It's written in a similar fashion as Kernigan and Ritchie's C book. It starts at the very beginning and doesn't make too many assumptions about prior knowledge.

I learnt using this book:

It's really fantastic and covers everything you'll need for making Cocoa Apps. A lot of the stuff you'll learn there is directly transferable to writing iPhone apps.

Another thing you can do is find a few open source iPhone apps to learn from, a good place to start would be, they have a bunch of examples apps you can take a look at.

If you're just looking for an obj-c language guide Apple has a pretty good one:

I'm a Java guy who is familiar with Swing programming and recently just started out with iPhone programming. Boy the learning curve was steep and now I would like to start Cocoa development for desktop apps.

I've been reading on articles and considering buying few cocoa book to advance my learning, still I feel I don't fully get it yet. I started about 3 months back and pretty comfortable with XCode and Objective-C but developing cocoa for desktop apps looks like a different game from iPhone development.

My questions are:

  1. Suitable book to pick up and learn from.
  2. What blogs I should follow?
  3. Any code example I should look at to learn from.

I've been looking at Adium src and considering buying Cocoa Programming 3rd but the book looks like bunch of stuff I already kinda know.

Suitable book to pick up and learn from.

What blogs I should follow?

Any code example I should look at to learn from.

EDIT: There is already a comprehensive list here on SO: Good ways to Learn Cocoa?

I'm working through Cocoa Programming for Mac OS X (3rd ed) and in chapter 4 I wrote this app:

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    //create the date object
    NSCalendarDate *now = [[NSCalendarDate alloc] init];

    //seed random # generator

    NSMutableArray *array;
    array = [[NSMutableArray alloc] init];
    int i;
    for (i=0; i<10; i++){
        //create a date/time that is 'i' weeks from now
        NSCalendarDate *iWeeksFromNow;
        iWeeksFromNow = [now dateByAddingYears:0

        //create a new instance of lottery entry
        LotteryEntry *entry = [[LotteryEntry alloc] init];
        [entry setEntryDate:iWeeksFromNow];

        [array addObject:entry];
        [entry release];
    [now release];
    now = nil;

    for (LotteryEntry *entryToPrint in array) {
        NSLog(@"%@", entryToPrint);
    [array release];
    array = nil;

    NSLog(@"about to drain the pool... (%@)", pool);
    [pool drain];
    NSLog(@"GC = %@", [NSGarbageCollector defaultCollector]);
    return 0;

The LotteryEntry class looks like this:

@implementation LotteryEntry

- (void)setEntryDate:(NSCalendarDate *)date
    entryDate = date;

- (NSCalendarDate *)entryDate
    return entryDate;

- (int)firstNumber
    return firstNumber;

- (int)secondNumber
    return secondNumber;

- (id)init
    return [self initWithDate:[NSCalendarDate calendarDate]];

- (id)initWithDate:(NSCalendarDate *)date
    if(![super init])
        return nil;

    NSAssert(date != nil, @"Argument must be non-nil");

    firstNumber = random() % 100 + 1;
    secondNumber = random() % 100 + 1;
    entryDate = [date retain];  
    return self;

- (NSString *)description
    NSString *result;
    result = [[NSString alloc] initWithFormat:@"%@ = %d and %d",
              [entryDate descriptionWithCalendarFormat:@"%b %d %Y"],
    return result;

- (void)dealloc
    NSLog(@"deallocating %@", self);
    [entryDate release];
    [super dealloc];


As you can see I'm retaining and releasing the objects here. I'm pretty sure my code matches the book's, however when I run the app, at the [pool drain] I get this message:

Program received signal: “EXC_BAD_ACCESS”.

I'm not sure what's causing this. I'm hoping it's something stupid that I missed, but I'd sure appreciate a few other pairs of eyes on it. Thanks in advance!

(side note: I'm a .NET developer, so ref counting is pretty foreign to me!)

doh! Just typing the code made me realize my problem. Doncha love it when that happens?

I am retaining the date in my init, but I still had that extra setEntryDate method that was not calling retain. Removing this and calling the initWithDate method instead seemed to fix the problem.

I've done a bit of iPhone programming (even have 1 published app) but what I'm really interested in doing is learning to create applications for OS X. I'm a 7 year .Net Developer so I have some understanding of how to make desktop applications, though I don't know much about memory management as .Net spoiled me. I was hoping someone could point me in the direction of a good tutorial for Objective-C/Cocoa but SPECIFICALLY targeting networking protocols as the application I have in mind would need to have networking capabilities (it's a turn based game with included chat). Everywhere I look for tutorials these days leads me to iPhone and Cocoa-Touch tutorials but I need desktop tutorials.

You're probably gonna have to tackle the two subjects separately. For general desktop app development, Aaron Hillegass' book Cocoa Programming for Mac OS X is the most often recommended. It also covers memory management, though if you've already gotten an iPhone application published, I presume you've already tackled the subject.

For networking, Apple provides Getting Started with Networking, Internet, and Web, which is a bit broad, but leads to Introduction to Stream Programming Guide for Cocoa, which in turn contains the chapter Setting Up Socket Streams.

Also keep in mind, OS X is a Unix™ platform, and Objective-C is a superset of C. This means you can eschew Cocoa entirely and use the BSD socket API directly using standard C syntax—meaning you can just Google "bsd socket tutorial" and you're off to the races.

Possible Duplicate:
Developing for the Mac?

i dont know anything about mac os x developing .

if i want to start developing and learning in "mac os x" then what i have to do?

which software i have to download ?

which book i have to read ?

any good material for that ?

Here are two book recommendations:

1) About the language Objective-C which is used for OS X development: Programming in Objective-C 2.0

2) Great book about application programming on the Mac: Cocoa Programming For Mac OS X

I am in the process of starting a project and whilst the logic part is relatively simple for me to mull through I am not very experienced with creating GUIs.

If you are not familiar with node based workflow here are a few examples

Nuke (The Foundry)

enter image description here

Max/MSP (Cycling 74)

enter image description here

SoftImage (AutoDesk)

enter image description here

The problems I have is where to start, What kind of object should I use to encapsulate the node gui? Or How would I go about making custom GUI elements that are click-drag/movable within a workspace? Are there any Books you recommend or anything you can link me too that would be able to get me up to speed.

Thank You

I recommend you use interface builder and the AppKit framework. A good introductory book is Cocoa Programming for Mac Os X

I have a week long holiday without 'net access coming up. I'm interested in learning iPhone development. What applications, tutorials, documents and so forth should I download in order to learn and develop iPhone applications completely offline? Are there any steps I need to take to prepare my iPhone to have apps loaded on to it while I still have 'net access?

The only thing you really need is a mac and the SDK. If you're registered as a developer, download either 2.2.1 or the newer 3.0 beta. The 2.2.1 version is fine for learning on, at least until you want to start uploading apps. Make sure the documentation you need is downloaded by subscribing to it. Click Help->Documentation and on the left, you can see the documentation sets. Click subscribe for the ones you want, or all of them if you're not sure.

You now have everything you need to start learning. If you want to try installing programs on your iPhone, you'll need to get a developer certificate and generate your keys. This is tricky and takes time to get right. If you don't want to do this, just use the iPhone Simulator, which is included in the SDK. Before you leave, download the Hello World program from the site and try running it in the SDK. If you can "Build and Go" and see the iPhone Simulator, you should be set.

If you're new to Objective-C, pick up "Cocoa Programming for Mac OS X (3rd Edition)" by Aaron Hillegass. The teaching style is great and he explains the basics really well. The book is aimed at desktop programming, but there is no better introduction to Objective-C.

If you need something more iPhone specific, get "Beginning iPhone Development" by Dave Mark and Jeff LaMarche. They have very in depth examples. The teaching style isn't as clear and the chapters are very long and involved but it's thorough.

If you need another book, get "iPhone SDK Development" from Pragmatic Programmers. It's a beta book, so there will be a few mistakes, but the style is much clearer and the chapters are a much more digestible length.

Any one of those books will take you much longer than a week to digest, but they're good starting points. There's no harm in downloading the Stanford podcasts too for when you can't read any more, but they're no good as stand-alone guides. Don't forget to download all their PDFs which have some great exercises.

Good Luck!

I'm a C# development. Mainly web services, ASP.NET, ADO.NET.

A guy wants to me to work build an iPhone app for him, from scratch.

What do I need to know/do to get setup to start developing? I hear objective C is the language?

I would probably either borrow or buy a copy of Cocoa Programming for Mac OS X by Aaron Hillegass. It is arguably the best book out there for learning how to write Cocoa code from scratch.

After that, I would do a couple of minor sample apps on the Mac. Then naturally, you will need an iPhone developer account to get the sample code from Apple. Coding for the Mac and Coding for the iPhone aren't that different, the knowledge is totally transferable.

To push code to the device, you will need to pay the $99 and get accepted into the developer program. But you don't need that to get started, the free account will get you into the developer area and allow you to download the SDK that comes with XCode and the iPhone Simulator. The getting started videos and documents will make sense once you have thumbed through the book.

It isn't all that different than C#, except no garbage collection, it uses reference counting like the Mac, and the use of the "[ ]" tokens everywhere takes a little getting used to.

It will be a noob question, but i'm getting crazy with this. I've read a tons of topics but i think i am missing something main.

I`ve created new cocoa app project, did not change anything, just add next code to main.m

int main(int argc, char *argv[])
    NSView *superview = [window contentView]; 
    NSRect frame = NSMakeRect(10, 10, 200, 100); 
    NSButton *button = [[NSButton alloc] initWithFrame:frame]; 
    [button setTitle:@"Click me!"]; 
    [superview addSubview:button]; 
    [button release];
    return NSApplicationMain(argc,  (const char **) argv);

During compiling xcode tells me that window undeclared. I understand that instead of window should be name of my NSWindow object, but i don`t understand which name has NSWindow which automatically created in MainMenu.xib file.

Please help, i`m almost ready to broke the wall with my head.

At that point no window has even been created yet. The code generated by Xcode gives you window in your projects application delegate, so add your code to -applicationDidFinishLaunching: in YourProjectAppDelegate.m instead.
I recommend to start with some introductory material like Hillegass where such things should be covered in detail.

I want to learn more about XCode, so I created an application that is intended for general desktop/laptop use, but not for iPhone.

It has AppController built on #include "Foundation/Foundation.h" and using files that I named AppController.h, AppController.m, and the MainMenu.xib file that was generated by the development system.

Now I want to add a subview. As I work though the problem, I'm obviously leaving out something or I'm incorrectly coding something. I can find many tutorials that provide a list of steps that are intended for iPhone applications, but none that fit my non-iPhone project.

Here's a chapter from Aaron Hillegass's book that shows how to do custom views and explains the view hierarchy.

There's also a "View Programing Guide" available on Apple's web site.

I'd very much recommend buying the physical book of "Cocoa Programming for Mac OS X" and going through each of the chapters and doing each of the practice apps. You might think it expensive, but it's absolutely worth every penny. It one of those resources I used way back when I wanted to become a hardcore Cocoa engineer.

Well, I've started with iPod/iPhone programming using Head First iPhone Development (O'reilly) and I'm typing code out of the book. There are two problems, one is programming related and the other is not.

  • I don't understand the format of objective-c methods. I'm getting an few errors now, based on source code from the book. Which leads me to my next issue.

  • Some of the code is buggy. I think so because I couldn't get the code to run without modifying it. The book has some typos in the text since it's a first edition and whatnot, but could my "fixing" the code have to do with it?

So... Where can I learn more about objective-c methods and how they work in terms of structure and where the return type and arguments go?

For those with the book, I'm in the middle of the InstaTweet app towards the beginning.


Read Cocoa(R) Programming for Mac(R) OS X (3rd Edition), it's the bible for Mac and Cocoa.

I haven't had any issues with it but keep in mind that API are always moving forward so there might be slight updates/changes. But I haven't found anything that would stop me from finishing all the code examples and exercises.

This is THE book to read.

Been looking for a book or a nice blog to jump into coding a gui app for mac os x. Everything thing I find for using xcode 4 is just for iphone dev. Anyone have any books or blogs or video tutorials I can take a look at?


This is a good book that focuses on cocoa programming. The updatet version will be published in November and should also include examples in Xcode 4

got a quick question for you (pretty much the title): is the book Cocoa Programming for Mac OS X (3rd Edition) outdated?

It's just that I read a little in it, until page 36 (in a .PDF ebook version) where I came across a problem. The chapter introduces you to Objective-C and Cocoa, and you already have to write a program by yourself. Exciting. But when he makes a class called Foo.h and Foo.m, my Xcode doesn't follow the guide.

  1. His Interface Builder is different from my Interface Builder.
  2. When he is about to make outlets and actions, I can't do it. They just won't show up.

I am sure I entered the correct info in my Foo.h file:

#import <Cocoa/Cocoa.h>

@interface Foo : NSObject {
 IBOutlet NSTextField *textField;


the Foo.m file:

#import "Foo.h"

@implementation Foo


and I dragged them both to the "Class" folder, but it still won't show them in IB. Besides that, Xcode shows three warnings:

  • Incomplete implementation of class 'Foo'
  • Method definition for '-generate:' not found
  • Method definition for '-seed:' not found

This is why I think the book is outdated, but these are not errors, just warnings.

Here's some screenies:

How his looks vs. how mine look

How his looks vs. how mine look

This just made me think that the book might be outdated, and if I can use it all (if there are mistakes in every chapters). Is it me that made a stupid mistake, or is the book really outdated?

Please help me out on this one, as I really want to learn Objective-C and Cocoa :) Thank you.

The book worked fine when I started building apps on Snow Leopard. A few things like "NIB" vs. "XIB" crop up, but the concepts are the same. Now on to your problem.

You won't see any connections in the Identity tab for your class when using a version of Interface Builder that is later than was used in the book. You want the connections tab for that.

Best I can tell from your screenshots, your class is in IB but the connections aren't listed. Are you actually referencing the correct class? Perhaps you have a few "foo.h" files floating around and grabbed the wrong one. Here's how to tell. Open the Library window in IB if it's not already open. In the search box at the bottom, type "foo". alt text

In the pulldown that says "Inheritance", change it to "Definitions". You'll see something similar to this: alt text

If it doesn't say "2 actions, and 1 outlet", you've got the wrong file (I know your file works because I pasted it in to write this up). Confirm the contents of the file that IB is using by clicking "foo.h". That will open the file in Xcode. Make sure it contains what you think it contains.

I am just beginning to learn objective-c and I am looking for a good place to start. Every book I pick up starts off like I already know what an object is and what an instance of an object is. Is there anywhere online or in a book where the basics of objects and classes and other knowledge I will need to read the books that I currently have? Here are some of the terms I need to know that the books are already assuming I know:

Object-Oriented Terms

Class, Instance, Message, Method, Instance Variable, Inheritance, Superclass/Subclass, and Protocol

Any help is greatly appreciated. I am not a slow learner, it is just all of the information I have found on the language so far seems to start off like you already know the information and terms above. I just need to be pointed in the right direction. I have knowledge of other programming languages, I am just looking to add to my library.

I like the book by Aaron Hillegass - he of Big Nerd Ranch fame. Not sure about the object assumption stuff, but the book is quite good.

I really recommend you the Stanford video mentioned above by a user and read this book as well. Along your line, be sure to try code something by your self, take a look at the sample code that is provided on Apple's developer site. Remember that practice is the best way to learn.

I am new to Cocoa, but I would like to give a shot to a project for my college course in programming.

Basically what i am trying to achieve is a simple cocoa app that is able to read into a directory, make thumbnails of the supported files, and display the files when double clicked. Basically if you have ever seen ACDsee you know what i am trying to replicate (without any editing function or extra features: just read files in a dir using the hierarchy view on the left, and make a list of thumbnails on the right)

Not sure where to start; I know OBJ-C but i am totally new to graphical apps, so any suggestion about where to look would be really appreciated.


Cocoa(R) Programming for Mac(R) OS X (3rd Edition) is really good and will help a lot.

I am new to iPhone application development so that i want to learn cocoa touch framework.

As i want to read on cocoa touch framework if anyone can help me to find some good resources to learn the framework as

ebooks tutorials and videos

it will be very useful to me .

The search box is your friend :) There is a great discussion here: Howto Articles for iPhone Development Objective-C

Personally, I'd suggest starting with Aaron Hillegass' Cocoa Programming for Mac OS X and then read Beginning iPhone Development by Dave Mark and Jeff LaMarche.

Apple has a lot of resources on their site: iPhone Dev Center

I have an application in which I have to hit many web services in same class and from another classes also and I have to parse the data each time.I cant write the delegate methods for webservice hit and XML Parse everytime as its not a good programming practice. So I thought of maintaining common classes for 'webserviceHandler' and 'XMLParsingHandler' in which I will write delegate methods for web service and XMLParsing respectively. Now the problem is how to make it happen to call these delegates each and everytime I hit the webservice from another classes..?? Code for this is more appreciable.. Thanks in advance..

Cocoa Programming for Mac OS X Chapter 28. Web Services using NSXMLDocument

There is also an example from ADC SeismicXML using NSXMLParser

In Aaron Hillegass' Cocoa Programming for Mac OS X, the Raiseman application connects a button in Interface Builder (IB) to an NSArrayController with sent action -remove:. In the MyDocument class he implements two KVC methods:

- (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index;
- (void)removeObjectFromEmployeesAtIndex:(int)index;

When this button is pressed, the -removeObjectFromEmployeesAtIndex: method is called and the currently selected Person (Model) object is removed from the array.

  1. How does the remove: method used in IB cause the -removeObjectFromEmployeesAtIndex: method to be called?
  2. How do I reproduce this effect with an NSTreeController?

Would learning C before Objective-C be beneficial or just slow me down? My goal is to make some useful applications for OSX.

One of the best books is Cocoa Programming for Mac OS X 3rd edition by Aaron Hillegass. That will get you started in learning Objective-C. That would be a good investment to see if you like how Objective-C and Mac OS X programming is.

Yes I've seen questions like these before but they're all for people who basically want to start from scratch. I come from AppleScript Studio (for those who do not know it, it's AppleScript in Xcode with IB etc.). The only things new to me are related to interface and implementation files. In my code I've already written 2000+ lines of ObjC, so it's not the syntax. But I fail to understand inheritance, accessing variables from other class files, etc.. The way I use ObjC is having one NSObject in IB which its class is changed to something new by me and then all my code is written in that one implementation file. My biggest problem is finding out how to access parameters from other classes.

So do any of you have any tips on where to start? Normally I'd start from scratch with a book but I seem to fairly be able to write code as long as it's located in one big file...

Thanks for your help.

Although you understand Interface Builder, it's very clear that you don't understand Objective-C or Cocoa very well at all. You need to stop flailing around and give yourself a firm grounding in the language and frameworks. The only way to do this properly is to start at the beginning.

You should start by learning Objective-C properly. In my opinion, the best way to to this is to read Stephen Kochan's superb Programming in Objective-C 2.0. This will teach you how to write Objective-C properly and explain object-oriented coding, class inheritance and so on. You should read the book cover to cover and do all the exercises.

You should then read Aaron Hillegass' Cocoa Programming for Mac OS X which will teach you how to take Objective-C and marry it to Interface Builder and the Cocoa frameworks to produce working Cocoa apps.

You should also read Cocoa Design Patterns which will explain what the design patterns in Cocoa are and how to use them to your advantage to write Cocoa apps the right way.

I am new to iphone .How can i develop appstore using store kit .can any one explain the necessary steps ..Thanks in advance

1) You need a mac. If your on a budget get a macbook or mac mini.

2) Get the developer tools with the iphone SDK. This will give you GCC and all of the basic tools required. Its free but you do have to register at . You can pay the $99 later on when you actually are ready to sell an app in the app store.

3) You need to know objective C. If have C experience you can pick up objective C pretty fast. I recommend "Programming in Objective-C" by Kochan

4) Learn Cocoa. The book that really opened my eyes to this was "Cocoa Programming for Mac OSX" by Aaron Hillegass. Any of the Aaron Hillegass books are great. I think he has some specific stuff to the iphone now as well.

5) Learn Cocoa Touch. I would use the online documentation. Its gotten me pretty far.

At this point your off to a good start. I highly recommend reading the apple documentation and using google. If you like to learn by looking at working code, Apple also has allot of ready made simple apps. There is allot of information out there for people willing to look it up. Don't be afraid to ask questions here but be specific and provide lots of details. No one started out knowing everything. I wish you happy learning and good luck.