DEVELOPERS

Hints and Tips

by Andrew Stone

Although NeXTSTEP 3.0 promises binary compatibility with NeXTSTEP 2.1 applications, developers have a little work to do to get their 2.1 applications to recompile in the new OS. Once you've done the conversion, you'll be rewarded with smaller and cleaner code that compiles faster.

Stop! Before you do anything, make backups of all of your existing source directories. Once you open a file with 3.0's Interface Builder (IB), you won't be able to open it again with the 2.1 version.

Choose a program to convert and double-click its IB.proj file. Project Builder (PB) will start up and convert IB.proj into PB.proj. The new program takes over all of IB's project-management functions, like maintaining the Makefile, making the new IB simpler and cleaner. The .nib files will be automatically converted when you edit them.

To create a new project, follow these steps:

1. Launch both PB and IB.

2. Make a new file by pressing Command-n in IB.

3. Save it in a new directory with the same name as your app.

4. Edit your .nibs by double-clicking their names in PB's browser.

5. New classes will be automatically added to your project as you create them inside IB.

Precompiled headers
NeXTSTEP 3.0 now has precompiled headers, which means that the class definitions for the entire Application Kit get brought into your program with the one statement: #import Be sure that this is the first #import in your source file, or else the precompiled headers won't work properly.

You can also precompile your own headers, which avoids having to #import 15 or 30 different files and speeds compiling as well. For Stone Design's 3DMan, I created this ProjectIncludes.h file:

	// System include ?????files
	#import 
	#import 
	#import <3Dkit/3Dkit.h>

	// Your commonly needed objects:
	#import "cFunctions.h"
	#import "localization.h"
	#import "SDLibBundle.h"
Then I added these lines to my Makefile.preamble file:

	# name of precompiled header created:
	$(OFILE_DIR): 3Dincludes.p

	# set this to the path where the includes live
	FILEPATH = /Net/blackhawk/Projects/3Dman

	# the makefile command
	3Dincludes.p: $(PSWFILES:.psw=.h) $(CLASSES:.m=.h) $(HFILES)
	cc -precomp $(CFLAGS) $(FILEPATH)/3Dincludes.h

New locations of #include files
NeXT has moved around all of its #include files, placing most of Berkeley's into /usr/include/bsd. If you try to compile your old code without modification, you'll see a lot of these warning messages:

	/NextDeveloper/2.0CompatibleHeaders/cthreads.h:1: warning: 
	Compatibility file included, use 

The way around this problem is to comment out all of the #include and #import statements in your code and replace them with a single #import . (Don't worry Ð most of the things that you might want to import have already been precompiled into appkit.h anyway). Add back the old #import and #include directives only if needed.

Objective-C comments in .c files
NeXTSTEP 3.0 ships with GNU C Compiler version 1.96, which is much pickier about its input source. For example, you can no longer have Objective-C statements in files with a .c extension.

Fortunately, there are two simple workarounds. Either change all of your .c files into .m files, or include this line in your Makefile.preamble:

	CFLAGS = -ObjC

Allowing an empty selection in a radio matrix
NeXT has changed some class names for consistency with the rest of the AppKit. For example, the Matrix method allowEmtpySel:(BOOL)flag has now been replaced with two methods: setEmptySelectionEnabled: (BOOL)flag and (BOOL)isEmptySelectionEnabled.

Interapplication messaging with remote objects
Say goodbye to having to use the AppKit classes Speaker and Listener. NeXTSTEP 3.0 now allows you to send messages directly to the Work-space Manager (and other apps) to make it do what you want.

For example, if you want to get an NXImage for a file icon under NeXTSTEP 3.0, you can simply do this:

image = [[Application workspace] getIconForFile:fileName];
Andrew Stone is president of Stone Design.