Page 1 of 2
 1  2  >
Reply
   
 chrome's cocoa coding calisthenics! exercise 1 
 
 
  #1 (permalink)  
Old 03-04-2008, 09:18 PM
Regular

Join Date: Jan 2006
Group: Regulars
Location: Sydney, Australia
Posts: 269


Lightbulb chrome's cocoa coding calisthenics! exercise 1

I was reading the various forums, and noticed one forum (I forget which) that has a regular coding exercise, to help people learn a bit more about coding. And I thought to myself, why don't we do that, but with a Mac OS spin, teaching Cocoa, Objective-C and C.

So I'm intending to semi-regularly (once a fortnight? or so) post an exercise for people to do. I will give some hints on what documentation to do, and some hints on probably pitfalls you will hit.

Every exercise will hopefully give you a working application of some kind, that probably won't be very useful, will be easily completed in an afternoon, but will help you get started in your path to learning Cocoa. The goal is to work through a bunch of exercises that will give you some experience with the Cocoa frameworks and the std C library to the point where you will be confident enough to take what you've learned and implement something useful.

I'm running a channel on the MTAU IRC server called #cocoa. Please join if you have questions! For details, see the Moofspeak IRC Network website.

Firstly some requirements:

  • You need Mac OS 10.5. I don't have Tiger, and the coding methodology has changed considerably between 10.4 and 10.5.
  • You'll need the Developer tools installed. You can find them on your Leopard DVD.
  • You need to not be afraid to use google and the Documentation that comes with Xcode. There are a wealth of resources out there to help starting Mac programmers. I'm not going to hold your hand and teach you how a switch statement works; all of this stuff is out there on the net. Again, if you get really stuck, join #cocoa.

OK, so lets get started!

Exercise 1
The useless text widget application.

You will create an application that has three widgets; an NSTextEntry, an NSTextView and an NSButton.

The application will not allow edits to the NSTextView widget, and text entered into the NSTextEntry will append the text to the end of the NSTextView. Furthermore, pressing the button (labelled "Insert") will also append the text, as will hitting the enter key.

The application will look like this:



The widgets should resize with the window correctly. The menu is not important at this stage.

Hints.

Read Long Pointers XCode 3.0 Tutorial

This tutorial gives you an application similar to what we're after, however it will require small modifications to provide an application meeting the exercise requirements. It co-incidentally introduces you to most of the things you'll need to be familiar with to build apps using Cocoa and Xcode.

In the NSText documentation, you will find a link to a document that explains how text widgets work in Cocoa. There is a section there called "Simple Text Tasks" that you will find helpful in implementing the code required.

Rules.

Please don't post your code in the forum until the exercise is completed. Its ok to ask questions, but please don't try and give the complete answer.

If you get stuck, or just want to talk about Cocoa and programming in general, join me on the MTAU IRC server, in #cocoa.

Feel free to post a download to your application for people to try, but people should be aware that we can't virus check or verify these files. If you download applications written by MTAU users and run them, you do so at your own risk

Last edited by chrome : 03-04-2008 at 09:45 PM.
chrome is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #2 (permalink)  
Old 03-04-2008, 09:22 PM
I'll do it soon, okay?

Join Date: Jan 2004
Group: Administrators
Location: St. Albans, Melbourne
Posts: 10,343


Excellent idea!
decryption is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #3 (permalink)  
Old 03-04-2008, 09:28 PM
Regular

Join Date: May 2005
Group: Regulars
Location: Sydney
Posts: 116


Good on you Chrome,
I am going to try and keep up with this
Martyb is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #4 (permalink)  
Old 03-04-2008, 09:30 PM
Regular

Join Date: Jan 2005
Group: Regulars
Location: Melbourne
Posts: 576


Here's hoping a few people from Adobe play along....
__________________
Successful Trades: milliedog; Jimdrum
El Guardo is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #5 (permalink)  
Old 03-04-2008, 09:32 PM
Regular

Join Date: Sep 2007
Group: Regulars
Location: North Coast NSW
Posts: 432


Cool - These might help me get off my butt and learn some OS X programming
__________________
2.4GHz 20" Alu iMac.
Aaron is online now
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #6 (permalink)  
Old 03-04-2008, 11:32 PM
Regular

Join Date: Apr 2005
Group: Regulars
Location: S37°56.2' E145°07.6'
Posts: 548


Hey this is a great idea.

An easy start but assuming this gets harder it should be fun for all of us.

Here's a zipped up copy of my solution: Exercise1-toholio.zip

Only took a couple of minutes and seven lines of code (including the class declaration and other cruft).

Obviously these are going to be simple for a lot of us, at first, and tricky for newcomers. How challenging do you expect to make them later on chrome?
toholio is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #7 (permalink)  
Old 03-04-2008, 11:36 PM
Regular

Join Date: Jan 2006
Group: Regulars
Location: Sydney, Australia
Posts: 269


Well, to start with, very basic. Just introducing people to methods for accessing controls, hooking into events, mucking with the storage types, etc.

Then, I'll probably look at networking a little later, building on what has been learned. Maybe an IRC client or something like that

The main thing is, I have to build it first, to work out what the gotchas are, and I'm learning cocoa from scratch too. So, anything more advanced than what I can do, is too advanced
__________________
Mac Pro 2 x 4 core 2.8Ghz 16GB | Mac Book Pro 17" | iPhone 3G 16GB | 20" iMac 2 Core 2 Duo
chrome is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #8 (permalink)  
Old 03-04-2008, 11:43 PM
Regular

Join Date: Feb 2007
Group: Regulars
Location: Adelaide
Posts: 257


I must say this one is simple for anyone with cocoa experience, but its a great idea and might get some interest going, i mean the framework flows onto the iPhone as well so people can take this experience and with a bit more effort make a iPhone app
__________________
Check out my cool applications:
InsomniaX | WiFiScriptor | Utility-Lock (SleepLock/AutoLock) | SyncBar
semaja2 is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #9 (permalink)  
Old 03-04-2008, 11:56 PM
Regular

Join Date: Jan 2007
Group: Regulars
Location: Melbourne
Posts: 1,575


A good tutorial for Xcode, however I personally prefer to design my User Interface first so I know where I am going.

Ricky.
__________________
It's one thing to nod, it's another to know.
rickyd is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #10 (permalink)  
Old 04-04-2008, 12:08 AM
Regular

Join Date: Jan 2006
Group: Regulars
Location: Sydney, Australia
Posts: 269


Ricky,

You can do that just fine. Design the interface, go implement the controller/delegate, with the outlets and actions, and then go back to IB and hook them up. Its not really important how you do the exercises, as long as you get there in the end
__________________
Mac Pro 2 x 4 core 2.8Ghz 16GB | Mac Book Pro 17" | iPhone 3G 16GB | 20" iMac 2 Core 2 Duo
chrome is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #11 (permalink)  
Old 04-04-2008, 12:09 AM
Regular

Join Date: Jan 2007
Group: Regulars
Location: Melbourne
Posts: 1,575


Quote:
Originally Posted by chrome View Post
Ricky,

You can do that just fine. Design the interface, go implement the controller/delegate, with the outlets and actions, and then go back to IB and hook them up. Its not really important how you do the exercises, as long as you get there in the end
I know
__________________
It's one thing to nod, it's another to know.
rickyd is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #12 (permalink)  
Old 04-04-2008, 08:15 AM
MacTalk Podcaster

Join Date: May 2004
Group: Regulars
Location: Melbourne
Posts: 1,636


Quote:
Originally Posted by toholio View Post
Hey this is a great idea.

Only took a couple of minutes and seven lines of code (including the class declaration and other cruft).
For those of us with a bit of Cocoa experience the real challenge lies in writing it with the least amount of code.

Because code is evil and should be avoided at all costs
__________________
garethtownsend.info

Melbourne Cocoaheads! - we're cuckoo for cocoa apps!
Quamen is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #13 (permalink)  
Old 04-04-2008, 05:32 PM
Regular

Join Date: Apr 2005
Group: Regulars
Location: S37°56.2' E145°07.6'
Posts: 548


Quote:
Originally Posted by Quamen View Post
Because code is evil and should be avoided at all costs
Exactly!

But seriously, I didn't avoid code. There simply wasn't anything more to write

Most of the people doing this will need more code though because:
  • They'll have header files.
  • They'll have variable declarations and whatnot.
  • They'll have pre-processor directives (#include and so forth.)

In short, most people will have written their solutions in Objective-C.
toholio is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #14 (permalink)  
Old 04-04-2008, 11:13 PM
Regular

Join Date: Jan 2006
Group: Regulars
Location: Sydney, Australia
Posts: 269


Seeing as this was so easy, I'll get another one up in a day or so. Also, if someone has suggestions, feel free to drop by on irc and have a chat
__________________
Mac Pro 2 x 4 core 2.8Ghz 16GB | Mac Book Pro 17" | iPhone 3G 16GB | 20" iMac 2 Core 2 Duo
chrome is offline
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
  #15 (permalink)  
Old 05-04-2008, 12:01 AM
Regular

Join Date: Mar 2007
Group: Regulars
Location: On a hill in WA, enjoying myself
Posts: 1,385


Thank you so much for doing this! I'll get started on this as soon as my iMac arrives.
__________________
 iPhone v1.1.3, Macbook C2D 2ghz. iMac alu. 20" C2D 2ghz. iMac 20" CD 2ghz & Cube 450mhz.

Bisho's blog Thoughts and musings of a bored person
Flickr - updated regularly
Older photo's - here
Lutze is online now
Profile CardPM
Go to the top of the page
Digg this Post!Add Post to del.icio.us Share on Facebook
Reply With Quote
 
Page 1 of 2
 1  2  >
Reply

Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding. Where to start? Lachie Terminal, UNIX, Command line & X11 32 07-04-2008 01:27 AM
Email coding vid Mac OS X & All Software 8 19-10-2005 12:53 PM
html coding Jimbo Projects: Audio, Graphics, Video, HTPC and Programming 22 18-02-2005 08:38 AM