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
