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.

Learn Cocoa


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.
Design Element
Learn Cocoa Tutorial Updated for Leopard
Posted Dec 24, 2007 — 30 comments below




 

StuFF mc — Dec 24, 07 5274

Perfect for my Xth time trying to learn Cocoa ;) Everything now looks good for me to make a brand new start in January. Can't wait the "Learn iPhone Cocoa" somewhere in March ;)

Damien — Dec 24, 07 5275

Hi,

With which tool did you create your arrow ? :)

Scott Stevenson — Dec 24, 07 5276 Scotty the Leopard

@Damien: With which tool did you create your arrow

Illustrator for the basic shape and Photoshop for the extra effects like shadow and sheen.

Takashi Yoshida — Dec 24, 07 5277

Hi Scott,

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

Scott, what's your take on NIB/XIB. Should we not now use XIBs everytime? I know they have the disadvantage of having to be compiled (right?) but they just kept on hammering us "XIB" during the WWDC...

StuFF mc — Dec 24, 07 5279

Oh and BTW, is the "learn_cocoa_two" still good for Leopard? Or are you planning to update it soon? Also, does anybody know if the "Bible" (from the Nerd Ranch) will be soon updated for Leopard?

Takashi Yoshida — Dec 24, 07 5280

Hi Scott,

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

Sorry about that. I should have looked before. "We are working on a third edition -- it should be out in the spring of 2008."

I'm not crazy about books, what's your take on it?

Scott Stevenson — Dec 24, 07 5283 Scotty the Leopard

@Takashi Yoshida: 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 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 Scotty the Leopard

@StuFF mc: Scott, what's your take on NIB/XIB. Should we not now use XIBs everytime?
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 Scotty the Leopard

I just updated the tutorial. There are two new steps: adding an "orderFrontFontPanel:" action to First Responder, and connecting the "Show Fonts" menu item to the action.

Jeremy — Dec 26, 07 5290

Per paragraph user comments would be incredibly useful for this tutorial.

The django book's site has this integrated really well.

jburka — Dec 26, 07 5294

Okay. Possibly stupid question:

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 Scotty the Leopard

@jburka: but it only has two buttons...there's the project and the debug buttons, but no build button

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

Thanks so much. This is great. I've been trying to learn mac programming with no previous programming experience, and your tutorials have been the most helpful material I've found yet.

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 Scotty the Leopard

@jburka: but it only has two buttons...there's the project and the debug buttons, but no build button

The screenshots have been fixed. :)

jburka — Dec 27, 07 5300

Thanks, Scott... thought I was going crazy there for a while!

Don T. Kellogg — Jan 02, 08 5308

Scott I'm still having issues when doing this tutorial from scratch. I add the action and attach it to the first responder using the control key but it still does not work. When I build and run the project the show font is greyed out and I can't type anything. The color format panel works though.

Don T. Kellogg — Jan 02, 08 5309

Scott never mind I saved the project then did the build not it seems to work fine. Just one of those ID10T errors =8^)

Kyle Zaragoza — Jan 07, 08 5321

Hi, I really enjoyed your first tutorial but its a real bummer that the 1st is written for leopard and the 2nd is still just slightly outdated. I was just wondering if you plan on rewriting any of the others? I got as far as dragging the AppController into the .nib file but it didn't allow me to. :/

Scott Stevenson — Jan 08, 08 5322 Scotty the Leopard

@Kyle Zaragoza: I was just wondering if you plan on rewriting any of the others

Yes. It takes a long time to redo all the screenshots and test everything, though.

E. Sabpisal — Feb 09, 08 5467

Thanks for the great tutorial

Derick — Apr 05, 08 5704

Any chance of updating Learn Cocoa II? I can't figure out how to add the class to my nib in Leopard IB.
thanks

Scott Stevenson — Apr 05, 08 5705 Scotty the Leopard

@Derick: Any chance of updating Learn Cocoa II? I can't figure out how to add the class to my nib in Leopard IB.

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, I am trying to learn as well, but I'm using Xcode 3.0 too and am confused by all of this. You guys really ought to put up some kind of forum or something at CocoaDevCentral. Even if it's just comments it would help tremendously for the problem like we have now. I have no idea what to do here. Should I just go back and restart using Xcode 2.5? Is that what the rest of the site is based on?

Seriously, at the very least add comments to CocoaDevCentral

Steven Degutis — May 06, 08 5794

@Michael Allen

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 Scotty the Leopard

@Michael Allen: Seriously, I am trying to learn as well, but I'm using Xcode 3.0 too and am confused by all of this.

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

Thanks for the great tutorials! Attempting to get example 2 has been extremely difficult on leopard just by 'guessing' and using apple's documentation. As a Java developer, this IB beast looks like it is really great, but doesn't give you a great overview of how my pieces are fitting (or not fitting) together. Looking forward to more tutorials!

michael — Dec 03, 08 6552

Hi Scott,

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




 

Comments Temporarily Disabled

I had to temporarily disable comments due to spam. I'll re-enable them soon.





Copyright © Scott Stevenson 2004-2015