DirectNET

Data Center Management Solutions including UPS Systems, Data Center Cooling, KVM over IP & IP Power Strips, Server Racks and Server Rack accessories; KVM Switches and KVM Extenders; Rackmount Monitors and Rackmount Keyboards.


NAVIGATION
Home
Store
INSIDE MAC
Television Shows
Broadcast Shows
Daily News Shows
Special Shows
EVENTS
DAILY TIPS
Design
Mac OS X
Mac OS X UNIX
COMMUNITY
Surveys
NEWS
Current
Press
Archive
FEATURES
Editorial
Dr. Mac
Reviews
Reader Reports
RESOURCES
FAQ
Documentation
Learning Center
MAN pages
Glossary
Tutorials
Tips
Links

OUR PARTNERS

Tutorials 

Creating a Mac OS X application with no code!

By Tristan Harris, Contributing Editor

Many adopters of Mac OS X are loving their new system, but are also asking the question, how can I write software for this wonderful platform?  You may have heard the words, Carbon, Classic, or Cocoa casually mentioned in geek conversations, but what do they really mean?

Carbon, Classic, and Cocoa are development environments for Mac OS X in other words, different languages and frameworks for developers to write programs. Carbon is a way for developers with preexisting programs to tune them up for Mac OS X by modifying and changing the application's existing code to work with the new system. It also allows programs written in Carbon to work on both Mac OS 9 and Mac OS X. Classic isn't really a framework but a compatibility layer. It allows programs written for Mac OS 9 to work in Mac OS X, with no changes in code. Of course, the problem with Classic is that its programs do not inherit any of the great features of Mac OS X, including the Aqua interface, protected memory, and other Mac OS X only features. Finally, Cocoa is RAD, or a Rapid Application Development framework. It allows programmers to create extremely powerful programs with just a fraction of the code of say a Carbon application. This is the framework we will use today to write our own application in just a few easy steps!

To begin, you must make sure that you have installed the Mac OS X Developer Tools which come on a CD in ever Mac OS X store box. After installing the Developer Tools, locate and launch Project Builder in your /Developer/Applications folder. Project Builder is an Apple-made integrated development environment and was designed exclusively for Mac OS X.

After launching Project Builder, select New Project from the File menu. You will be confronted with the following dialog:

Select Cocoa Document-based Application from the list and click the Next button. Call your project, Text Editor and save it anywhere you like.

After clicking Finish, you will be confronted with your project's window. This is where all the code writing, adding and deleting of files, compiling, building, debugging, and running is done. Everything you need is at your fingertips.

From the project window, you can click on MyDocument.h or MyDocument.m and see some code that has already been written for you to handle the Document-based model we specified when we created our project. After you're done browsing through the project window, double click on My Document in the Groups Files area. This will signal a launch to Interface Builder, an application that allows you to literally build interfaces for applications, letting you add buttons, controls, sliders, text fields, and anything else that is a visual element in Mac OS X. Now, the first thing you should do after launching Interface Builder is to select Show Info from the Tools menu.

The Info window is a way for you to change the attributes of the items you add to your interface. For example, right after opening your .nib file, you should have the following windows on your screen:

You'll see in your Info window, you can now change the attributes of the window that is selected. You can change the window title for example as well as choosing which window controls are available: Miniaturize, Close, Resize.

Click on the Document Contents Here text item in the window. Delete it by hitting the delete key on your keyboard. Now we can have some fun. You'll notice you have a Cocoa-Views window that we will call the Palette. From the Palette, you can drag buttons, text, check boxes, radio buttons, or anything you want. But in our case, we will just drag in a text field item. This can be found by clicking on the cut off text with the scroll bars icon at the top of the Palette. This will then show you 4 different types of text fields. Drag the top-right most text field, beginning with the words, Lorem ipsum, into your document window. Resize the field and move it so that your document window now looks like this:

Change the attributes of the text field to your liking. For my text field, I checked the Graphics allowed and Undo allowed checkboxes. This will enable these features in your text field when our program is actually running.

Now, when you are done, save the changes to your MyDocument.nib file in Interface Builder and quit.

Go back into Project Builder, and click on the Build Run icon in the toolbar. Finally, look at what all your hard work has created! A full-featured Mac OS X Text Editor with absolutely no code on your part!

You'll notice you can even spell check in your new application by selecting Check Spelling as you Type from the Spelling item in the Edit menu. All of this works automatically! When you close the document, a sheet even comes up asking if you'd like to save the changes to your document.

Just imagine the incredible software you can make with all this great stuff for free, in this simple development environment.

If you're interested in diving deeper into the world of Cocoa, here are some links to sites with important information:

Apple's Cocoa Development Main Page

http://developer.apple.com/techpubs/macosx/Cocoa/CocoaTopics.html

Objective-C Language and Object Oriented Programming

http://developer.apple.com/techpubs/macosx/Cocoa/ObjectiveC/index.html

Its also important to note that after installing the Developer Tools, all the documentation for Cocoa is right there on your computer already! Just go into the Help Viewer application and click the circular button with a list of all the help files on your computer. Scroll down and you'll see, Developer Help Center which contains all the developer documentation you'll ever need. Good luck!

If you have any questions or comments about this article, feel free to e-mail me: tristan_harris@osxfaq.com

Copyright © 2000-2010 Inside Mac Media, Inc. All rights reserved.
Apple assumes no responsibility with regard to the selection, performance, or use of the products or services. All understandings, agreements, or warranties, if any, take place directly between the vendors and prospective users.
Apple, the Apple logo, Mac, PowerMac G4, PowerMac G5, Xserve, Xserve RAID, PowerBook, iBook, Airport, AirPort Extreme, iMac, eMac, iLife, iMovie, iCal, iPhoto, iTunes, QuickTime, FireWire, iPod, iSight, AppleWorks, Macintosh, Jaguar, Panther, Mac OS, Mac OS X and Mac OS X Server are trademarks of Apple Computer, Inc.