Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Recent issues

Article Preview

Buy Now

Issue 1.5


Instant Cocoa

Issue: 1.5 (April/May 2003)
Author: Colin Cornaby
Author Bio: Colin Cornaby is an OS X developer. He is currently working on a new project, which will probably be out by the time you read this.
Article Description: No description available.
Article Length (in bytes): 4,939
Starting Page Number: 43
Article Number: 1523
Related Link(s): None

Excerpt of article text...

In the last column we built a program in Cocoa that displayed a sheet attached to a window. You learned to create a class to hold your code, how to add an outlet to your class, and how to create an action. This time we'll create a new project that will create variables in Cocoa, retrieve data from your interface, and practice sending data from your code back to the user.

First, you need to create a new Cocoa application project in Project Builder. For this exercise, you can name it anything you wish (although I named mine RBDExampleApp). Be careful about giving your application a name with a space in it. Project Builder has issues with projects that have spaces in their names.

You should then open your nib and lay out the window to look like the one in Figure 1. You will need to add two text boxes, and a button. After you have laid out the interface, create a new class. Name your new class "interfaceController", and add two outlets to it. Name one outlet "firstTextField" and the other outlet "secondTextField". Also add an action called "moveTheText". Create the files for your class, and then instantiate the class. Link the outlets up to the appropriate fields (firstTextField to the first text field, secondTextField to the second), and link the button to the action. Remember that it matters which direction the link is drawn. Refer back to the last column if you need to. When you are done, save the nib and close Interface Builder.

We'll cover new topics now. Everything in the last few steps was covered in the last column, but probably isn't terribly comfortable for you yet. Don't feel bad if you have to re-read the exercise we did last time with our sheet project. Trying to code Cocoa doesn't come naturally without a lot of experience. The more you code in Cocoa, the more you will become used to the way Cocoa works.

Now go back to Project Builder and take a look at your interfaceController.m file. As you recall from the last column, the .m file holds your code, while the .h file holds your definitions. You should see an empty method for "moveTheText" in the .m file.

Now it's time to add some code. Enter the following into the "moveTheText" method:

...End of Excerpt. Please purchase the magazine to read the full article.