Learn Cocoa Tutorial Updated for Leopard
The Learn Cocoa tutorial at Cocoa Dev Central is updated for Leopard. It turns out this actually isn't as easy as just swapping a few screenshots in. Interface Builder was completely rewritten, so everything is in a new place.It's also challenging to come back to tutorial I put together a year ago. When I look at the same material, there are so many things I want to do over, but I also want to get it out as soon as possible. The result is something of a compromise. Some sections were completely redone, some things were left as is.
I think it's probably one of the most gentle, stress-free ways to learn the absolute basics of writing your first Cocoa app. It walks you through setting up a project in Xcode, creating a single window in Interface Builder, and testing out the result.
I hope you like it.
Learn Cocoa Tutorial Updated for Leopard
Posted Dec 24, 2007 — 30 comments below
Posted Dec 24, 2007 — 30 comments below
StuFF mc — Dec 24, 07 5274
Damien — Dec 24, 07 5275
With which tool did you create your arrow ? :)
Scott Stevenson — Dec 24, 07 5276
Illustrator for the basic shape and Photoshop for the extra effects like shadow and sheen.
Takashi Yoshida — Dec 24, 07 5277
Thank you for an excellent tutorial.
After going through the tutorial, I have a few questions.
1. My MainMenu.nib already has Format menu in the MainMenu. It is slightly different from yours (it has Format -> Show Fonts, Format -> Show Colors).
Did you delete the original Format menu in the MainMenu? I'm using Xcode 3.0 and Interface Builder 3.0.
2. After deleting the original Format menu, I dragged and dropped the Format menu Library palette. I built and run the CocoaNotepad but the Font and Text menus have most items disabled. For example, Show Fonts and Show Colors cannot be selected.
Are there any missing steps?
StuFF mc — Dec 24, 07 5278
StuFF mc — Dec 24, 07 5279
Takashi Yoshida — Dec 24, 07 5280
I downloaded the project files at the bottom of the tutorial. It seems like my project was missing an instance of NSFontManager in my MainMenu.nib file. I also had to connect the NSFontManager object to the Format menu items as well.
I'm not quite sure why I am having this issue but I'm glad I figured out what was wrong.
If any of you are having a similar issue, be sure to check out Scott's project files and see if you have anything missing in your MainMenu.nib file.
StuFF mc — Dec 24, 07 5281
I'm not crazy about books, what's your take on it?
Scott Stevenson — Dec 24, 07 5283
I didn't realize that the Leopard template adds a Format menu by default. That's my fault for not checking. The NSFontManager thing is not something you usually need to add yourself. It's only there because the project was created on Leopard.
However, it looks like there's a small bug in the Leopard version of Interface Builder that I didn't know about (but it's a registered bug). The built-in Format menu isn't wired up by default.
Here's the quick solution:
1. Leave the existing Format menu in place
2. Select the red "First Responder" cube in the document window
3. Choose Tools > Identity Inspector from the Interface Builder menu
4. Under "Class Actions" in the inspector, press the plus button to add a new action
5. Name the action "orderFrontFontPanel:"
6. Control-drag a connection from Format menu's "Show Fonts" item to First Responder
7. Choose "orderFrontFontPanel:"
Save it and it should work. This doesn't have all of the features of the full-fledged menu, but you can open the Font panel and get to most of them.
Scott Stevenson — Dec 24, 07 5284
I haven't looked at it closely. I use regular NIBs and that's probably fine in most cases. In theory, XIBs would fit better with diffs in subversion, but I have no idea how that fits together in practice.
Oh and BTW, is the "learn_cocoa_two" still good for Leopard?
Not really. The code parts are fine, but the directions for Interface Builder reflect the Tiger version. I'll update it as soon as I can.
I'm not crazy about books, what's your take on it?
I think Aaron's Cocoa books are some of the best available.
Scott Stevenson — Dec 25, 07 5287
Jeremy — Dec 26, 07 5290
The django book's site has this integrated really well.
jburka — Dec 26, 07 5294
When I followed the directions to switch to the all-in-one layout in XCode, I had the expected "Page" widget at the left side of the tool bar -- but it only has two buttons...there's the project and the debug buttons, but no build button.
I didn't see any way to change it by customizing the toolbar. And I tried reinstalling XCode from my Leopard dvd, but that made no difference.
Scott Stevenson — Dec 26, 07 5295
Apparently, projects created with an earlier verison of Xcode have three buttons (even when opened on Leopard), but new projects have two. I need to update the screenshots.
It actually doesn't matter which view you use in this case, though. You only interact with the file list long enough to open MainMenu.nib, and it doesn't matter which view you open it from.
Joey — Dec 26, 07 5297
I'm really looking forward to the updated Learn Cocoa II tutorial. I've been struggling to learn Interface Builder and Cocoa because of how different IB 3 is and all of the tutorials I can find show version 2. Even Apple's Currency Converter tutorial. So it's been a little confusing.
Thanks for all your great tutorials.
Scott Stevenson — Dec 27, 07 5298
The screenshots have been fixed. :)
jburka — Dec 27, 07 5300
Don T. Kellogg — Jan 02, 08 5308
Don T. Kellogg — Jan 02, 08 5309
Kyle Zaragoza — Jan 07, 08 5321
Scott Stevenson — Jan 08, 08 5322
Yes. It takes a long time to redo all the screenshots and test everything, though.
E. Sabpisal — Feb 09, 08 5467
Derick — Apr 05, 08 5704
thanks
Scott Stevenson — Apr 05, 08 5705
Yes. This specific issue is easy to solve, though: you don't need to add classes to Interface Builder 3. It automatically reads them from the Xcode project.
Michael Allen — May 06, 08 5793
Seriously, at the very least add comments to CocoaDevCentral
Steven Degutis — May 06, 08 5794
Your comment seems very unappreciative of the hard work that the authors of cocoadevcentral.com put into it while getting nothing in return. They don't need to do anything with the site, and what they decide to do, we should not take for granted. If you have a suggestion or comment, I recommend you give it as constructive criticism, not a demand.
And, regarding the differences between Interface Builder (and Xcode) 2.x and 3.0, I've had very little difficulty learning the new way to use it, especially when using documentation from Apple.com (including the Currency Converter), and I know many people who learned their way around the new app in less than a week. The trick here is probably not to feel too overwhelmed by all the differences between tutorials/documentation and the new version of IB3. Just relax and be persistent. If you truly do want to learn how to use it, you will find a way to do it, instead of complaining and being demanding.
Scott Stevenson — May 06, 08 5795
Everyone is at a different stage of knowledge with different needs. A lot of people wanted an Objective-C tutorial, for example, so I put one up recently.
Still, your point is taken. I understand how frustrating it can be to have something up that's wrong and you can't figure out why. The tutorials take far longer to put together than I think most people imagine, but what I can do in the meantime is put up a note that says "this won't work for Leopard yet."
RB — Aug 06, 08 6241
We wait for new tutorials !!!!!!!!!!!!!!
Jason — Aug 11, 08 6246
michael — Dec 03, 08 6552
I am new in the cocoa programming technique, with experience in assembler and Pascal, and I would like to say a big thank you Scott for your tutorials.
Cocoa is not easy, sometime difficult to grab the concept, and examples like you have published are very useful. Of course, the Aaron book is fine, but simple examples are missings (at least for my understanding ).
best regards
Michael