« Release of Family 2.0 | Main | Weekly Cocoa Challenge web page »

January 03, 2007

The weekly cocoa app challenge, week 1

So for a while now I've always been saying the best way to learn something is to keep trying it. For Cocoa I've been working on things called "stupid apps". Basically these are a set of applications that perform 1-2 tasks, help me learn a new thing, and allows me to continue evolving with Cocoa.

So the rules:

1) I will post a new mini "stupid" app once every week or two. Some weeks I get super busy, so I may skip a week every once in a while.

2) If you are learning Cocoa, you try to reimplement the application. I won't be including readmes or anything so you'll also need to figure out the functionality, the api used, and the general goal of the app.

3) When I post a new app, I will also post source code for the previous app.


Got it? If you don't, post a comment.

Anyhow, here's the first app. Have fun:

Dude, Where's My Package.app

Good luck, feel free to ask questions in the comments as well.

Posted by Chris Forsythe at January 3, 2007 10:36 PM

Comments

Finished. Ta da!

I think I’m wasting some memory (already).

Posted by: zaudragon at January 3, 2007 11:46 PM

Mmm,

You can do a ToDo simple, only add and edit the preferency of tasks, with categories, and in the icon of the dock show the taks uncompleted.

And a bonus with a sistem of skins like Adium, for this way put the program in desktop.

I search a program like this a long of time and I cant find none :(

I need it!!

PD: Sorry by my english, i am from spain :)

Posted by: koronas at January 4, 2007 04:55 PM

How do you make the app exit when you close the window?

Posted by: Logan Williams at January 4, 2007 06:34 PM

Uhm, is that all...? Buttons that open web links?

Posted by: alimony at January 4, 2007 08:33 PM

alimony - Yea. And making the app quit when you close the window. I figured start out slow.

Logan - 2 ways:

-(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
return YES;
}

or as Takumi tried:

- (void)windowWillClose:(NSNotification *)aNotification {
[NSApp terminate:self];
}

Posted by: Chris Forsythe at January 4, 2007 08:41 PM

I give up - how do you make a button open a URL?
I got as far as having an NSURL object with a string as a URL.... lol

Posted by: Jasarien at January 5, 2007 08:10 PM

I'll post the source on Jan 09, maybe sooner.

I'm thinking of making a new page for this stuff. Where are you stuck?

Posted by: Chris Forsythe at January 5, 2007 08:16 PM

One hint, use "show package contents", and look at the nib file.

-jcr

Posted by: John C. Randolph at January 5, 2007 11:31 PM

I did look at the nib file, it was one of the first things I did.
I have the AppController class all set up and all the connections to the actions fine. It't just implementing the class that I'm stuck with :P

Posted by: Jasarien at January 6, 2007 12:17 PM

I'm still learning cocoa, so these types of small challenges are fun. Took 12mins 43 secs to completion. Keep the challenges rolling Chris :)

Posted by: Justin Prine at January 6, 2007 02:28 PM

Great idea Chris!
It's very useful and a good way to learn Cocoa :D

Posted by: Tulipe.Moutarde at January 6, 2007 05:34 PM

Done!

Posted by: Jason at January 6, 2007 11:55 PM

Did you make it exit the application when the window closes Tulipe?

Posted by: Chris Forsythe at January 7, 2007 12:00 AM

Very cool idea.

Funny, because it was only last night I dug out my Cocoa book.

Posted by: David Winter at January 7, 2007 06:01 AM

Great idea. Even though I'm not a beginner at Cocoa, I still learned something while doing this fairly simple challenge. I never had the occasion to make the terminate when the last window is closed before. I vaguely knew how to go about doing it, but now I had to look up the details and do it. So cool! I look forward to more challenges.

I'll be posting my solutions on my blog. Solution #1 is here:

http://www.smallbutdisorganized.com/2007/01/08/the-weekly-cocoa-challenge/

Posted by: Sean at January 8, 2007 01:23 AM

These challenges are exactly what I have been looking for to transfer my skills from a decidedly non-OO, non-Mac environment.

Thank you for putting them together.

@David Winter: Thank you for posting your solution. I was able to get a better understanding of what was happening thanks to your commented code.

Posted by: Tony Jensen at January 8, 2007 10:06 AM

This is an excellent idea. I look forward to seeing the next challenges.

I've put my solution here, if anyone's curious.

http://myztik.katan.com/?page_id=149

One question, though. How much of an exact duplicate are you looking for? I named mine the same as yours... even stole the icns file. Is that overkill?:)

Posted by: Myztik Jenz at January 8, 2007 11:44 AM

As much as you want to do Myztik.

Posted by: Chris Forsythe at January 8, 2007 11:52 AM

I do this too!

Although I call them "test apps" which basically encapsulate a small piece of functionality allowing me to effectively test it before integrating it into the app I'm working on.

Posted by: Keith Duncan at January 8, 2007 01:15 PM

Thanks for doing this. I just finished cocoa programming by Aaron Hillegass and am looking for small challenges. I had never used NSWorkspace or NSURL and this was a practical example to learn something about them. I could guess what the latter did but had no idea what the NSWorkspace did until you gave me a reason to read the docs. listing the api's used is a great way to get others out there and learn for themselves. the challenge may have been easy (especially after checking out the nib) but it still helped me learn.

i hope to see more of these challenges, so keep them coming!

Posted by: Clint at January 9, 2007 08:18 AM

this is a great idea! i just completed this (my first cocoa app after currency converter) and learned a lot. thanks :-)

Posted by: nico at January 11, 2007 04:45 PM

Question: if you set applicationShouldTerminateAfterLastWindowClosed: to YES, the application quits when you close the About window. That is hardly expected behaviour, is it? Any idea how to correct this? Thanks,
Marco

Posted by: Marco at February 1, 2007 04:15 PM

Post a comment




Remember Me?