A Roadmap Through Cocoa
There's a comment on the post for the first episode of Late Night Cocoa that caught my attention. The comment is basically a request for a roadmap through Mac OS X programming:One thing that did resonate with me was the comment on how many frameworks you had to get your head around and how long it took to get your first application up and running.
Maybe a roadmap [...] could be discussed here so experienced Cocoa programmers can help steer novices through this "forest" (thats what is seemed to me when I first started).
Do a lot of people feel this way? The thing that makes it hard to answer something like this is that there are a lot of frameworks, meaning there are a lot of possible roadmaps. If you're interested in making a game, you're going to have a different roadmap than someone making a mail client.
In other words, you don't need to learn all of the frameworks before you starting working on an application. In fact, choosing an application to work on might be a better guide than some sort of formal plan.
There are basics, of course. You need to understand Objective-C, and the basic ideas behind Foundation and AppKit classes. Key-Value Coding is the basis for a number of things, so that's important too.
If you want to manipulate data, Core Data can be an invaluable tool. After that, though, the field is wide open. Maybe your application benefits from WebKit, maybe it needs AddressBook. It just depends on what you're looking to do.

A Roadmap Through Cocoa
Posted Jan 20, 2007 — 34 comments below
Posted Jan 20, 2007 — 34 comments below
Ben — Jan 20, 07 3358
FWIW, the intro roadmap that worked great for me was going through the Hillegass book, chapter by chapter and challenge by challenge, which really gets you through all the fundamentals, and then studying the example Sketch app, which is a good primer on application architecture. (There still isn't anything in print for learning CoreData or CoreImage.)
Kyle — Jan 20, 07 3359
What if I need to access different classes from other classes? What's the best design for that kind of thing. Cocoa is a bit different and under normal conditions I'd understand this, but Cocoa confuses me in this respect.
Scott Stevenson — Jan 20, 07 3360
I believe Step in Xcode covers Core Data.
Scott Stevenson — Jan 20, 07 3361
There's no one rule for things like this. It really depends on the what your goal is. I don't even think it's something that's specific to Cocoa. Figuring out the design of things seems to come from experience more than anything.
That said, I get the question about "accessing different classes from other classes" quite a bit, and it usually ends up that the question itself is beside the point. Usually, there's a simpler way to what you want. Again, it just depends on the particular case. Feel free to post a simple example here if you want.
Richard Albury — Jan 20, 07 3362
I believe Step in Xcode covers Core Data.[/]
s/in/into/
Peter Hosey — Jan 20, 07 3363
Rob — Jan 20, 07 3364
Images of the typical interface implemented by the API or a flow chart for data or processes.
Stepping through from simple to complex, would be very helpful.
All the structs for simple to complex, grouped by simularity, with links to the Apple help page would be nice.
Notice how everyone is asking about their specific problems and can't express what they want specifically, if we had a road map then we could speak the same language and ask in terms of the APIs.
Chris L — Jan 20, 07 3365
Todd — Jan 21, 07 3366
A recent example: I have a client app, which sends commands to a server based on user actions. To get all keyboard input, I subclassed NSView and used keyDown to get the keyboard input. But, then I don't see how to get the keypresses back to my object that has the network connection, to send the command.
Peter Hosey — Jan 21, 07 3367
Scott Stevenson — Jan 21, 07 3369
You could either do what Peter says about NSNotification, or you could create a "_delegate" instance variable, so that your view does something like this in keyDown:
delegate = [self delegate]; if ([delegate respondsToSelector:@selector(viewDidReceiveRequest:)]) { [[self delegate] viewDidReceiveRequest:self]; }
And the delegate implements the method:
- (void)viewDidReceiveRequest:(id)theView { // do something with the network here }
The reference to delegate should not be retained. This is called a "weak reference."
Jonas Greitemann — Jan 21, 07 3371
With me coming from Java, I know this "can't get there from here"-feeling, as Todd calls it, very well. Cocoa's notifications and the strict separation of classes into Model, View and Controller are a huge advantage, so I don't have this problem any more.
Todd — Jan 21, 07 3373
Thanks for the responses. I've used nsnotification in another project, so I'm familiar with that. It just seemed like it was overkill for what I thought would be a simple thing.
I haven't created my own delegate methods before.. So, I think I'll give that a try & read up on it some more.
Thanks!
Scott Stevenson — Jan 21, 07 3375
A leading underscore usually means "private." All instance variables are implicitly private in Objective-C, so many experienced user simply prefix all of them with an underscore. Part of the reason is to avoid confusion with local variables. For example, take a look at this:
@interface DefinesTest : NSObject { id delegate; } @end @implementation DefinesTest - (void) talkToDelegate { id delegate = nil; } @end
This is, at best, simply confusing. Is the delegate declared in talkToDelegate a local variable or does it refer to the instance variable? If you add an underscore to the instance variable, you can easily tell the two apart.
Peter Hosey — Jan 21, 07 3376
My solution is to not give my local variables the same name as my instance variables. (In -initWithFoo: and -setFoo: methods, I name the argument variable newFoo.)
Scott Stevenson — Jan 21, 07 3377
Well it certainly used to. I just tried it on a stock Cocoa project template on Xcode 2.4 and it doesn't say a thing about it.
Brian Gilstrap — Jan 22, 07 3379
I have many (20+) years of serious development experience, including writing complex GUIs in Java. Before Java, I was doing C++ for five years of serious distributed systems development. I've been doing OO programming for over twenty years.
I want to use Interface Builder and key-value binding, since there is clearly a lot of power to avoid writing glue code. But I've found nothing that really pulls the concepts together in a good tutorial. Right now my biggest issue is knowing what can be connected to what in IB. Is there some crucial documentation that I've not found that describes the foundation classes in relation to key-value binding/coding?
Rob — Jan 22, 07 3381
That might be a good place to start.
Nick Rundquist — Jan 22, 07 3385
There are a lot of ways to get from Austin to Houston but you only need one map to see them all. I think what people are looking for is something less like the "roadmaps" we're used to in the tech industry, which tend to be one dimensional, and more like an actual two dimensional roadmap where you can see what your choices are. You say that there are a lot of frameworks but it's not even easy to find out what they are. The best list I could find is this. I don't know what others are looking for, but I've always wanted to see something along the lines of what Sun produces for Java. Indeed in general I have to say that I think Sun does a much better job structuring its Java documentation than Apple does its Cocoa documentation and it's this lack of structure that leads to a feeling of being lost in the forest.
Scott Stevenson — Jan 22, 07 3386
You wish that's all there was. :) I kid. The catch for Apple is that developers are constantly asking for more API to work with, so they have more to document.
In my opinion, the goal shouldn't be to get a comprehensive undestanding all of your options (at least not at first). To me, this is like somebody walking up and asking what all the options are for careers. I wouldn't even know where to start. I would need to have some idea as to what your interests are before I could make suggestions. Once you can give some sort of idea about what you want to do, it becomes much easier to make suggestions about how Cocoa and the related frameworks can help you do it.
I've always wanted to see something along the lines of what Sun produces for Java.
Do you have some examples? I'm open-minded to considering Sun has some good ideas here, but I'm not sure Apple and Sun really have the same sort of needs to address.
Nick Rundquist — Jan 23, 07 3387
Looking in
/System/Library/Frameworks/
I see your point. Now I want a roadmap just so I don't take a wrong turn and end up in the DiskArbitration framework.To me, this is like somebody walking up and asking what all the options are for careers. I wouldn't even know where to start.
Well, there is a giant book of careers put out by some branch of the US government, or at least there was when I was in high school. And I did peruse it out of curiosity. It's certainly not out the realm of possibility that I'm unique in my fondness for poking around in well structured data.
I'm not sure Apple and Sun really have the same sort of needs to address.
True enough. Since I wrote my initial post I've realized that what I liked about the Java documentation so much was that, being generated by JavaDoc, it shared its structure with the classes it was documenting. Lacking the notion of packages this doesn't translate over to Cocoa so well.
That said I still feel that beginners could benefit from some facile treatment of a broad range of subjects. Not necessarily explaining anything in depth, just pointing to the most appropriate documentation on the subject. How best to go about that, however, escapes me right now.
Peter Hosey — Jan 23, 07 3390
Not so. The trick is that it gives the warning on the use of the shadowing local variable, not the declaration of it.
- initWithFoo:(NSObject *)foo { //No warning here if((self = [super init])) { [foo bar]; //Warning here } return self; }
Rob — Jan 23, 07 3394
I hope you understand my langauge I am trying to be specific and in langauge geeks would understand.
Would it be possible to do a tutorial on how to implement Mole Code in Cocoa, I don't want it for hacking, it would probably need to be more capable for that, just for testing.
But that example could probably be used for internal app scripting and messaging so could have general use.
I would make a generous donation, $40?, for that too since it applies to my work.
mmalc — Jan 23, 07 3395
mmalc
Scott Lewis — Jan 31, 07 3468
It could be argued that much of what Obj-C/Cocoa/Xcode is doing is creating a better Smalltalk. I don't mean just the language, but the entire programming environment.
Dealing with the way Smalltalk handles the user interface clears up many of the mysteries of how Interface Builder works, as IB seems (to me) to be designed to overcome some Smalltalk limitations. Similarly, Smalltalk makes KVC seem very reasonable, as the alternative is a kind of "ritualistic" coding.
Also, exploring Smalltalk can help make your code much more fully object-oriented. For example, classic Smalltalk does not have anything like a "case" statement. Why? Because in classic O-O coding, you should always use polymorphism instead. Each object should know what to do when sent a standard message.
I would note, though, that I come from a background of studying English Lit, rather than Math or Science, so this could be a very idiosyncratic approach!
Rob — Jan 31, 07 3469
try
{ do something that can fail }
on error
{ do error alert or do nothing }
Scott Stevenson — Jan 31, 07 3470
Rob — Feb 01, 07 3476
... THANKS for the pointer to the @try in O-c that should work well.
And thanks for the way cool handle !!!
Rob — Feb 01, 07 3477
What is the easiest way to get work Xcoding Cocoa, low Cocoa requirements, 20 years test engineer experience ?
Rob — Feb 01, 07 3478
"To turn on support for these features, use the -fobjc-exceptions switch of the GNU Compiler Collection (GCC) version 3.3 and later."
Scott Stevenson — Feb 01, 07 3479
The Learn Cocoa tutorial might be a good start, along with with the C Tutorial. If you want a book, Cocoa Programming for Mac OS X by Aaron Hillegass is very good.
How do I do this? "To turn on support for these features, use the -fobjc-exceptions switch"
You just need to click the checkbox for "Enable Objective-C Exceptions" in build settings. The build settings panel is described here.
Rob — Feb 02, 07 3481
Although, while it now compiles it is still crashing ! I guess it took a while implement fully. I wish they would ship the flash laptops and Leopard so I could get up to date.
Actually, my other question was do you know of any places that are hiring O-c programmers, people that have a lot of Mac experience as say a tester but are just getting into O-c.
Thanks
Scott Stevenson — Feb 02, 07 3482
I don't know of any personally. You should keep an eye on the CocoaDev jobs board.
Rob — Feb 09, 07 3560
http://seashore.sourceforge.net/download.php