NeXT Question

by Simson L. Garfinkel

Q: What's the easiest way to put a printable ASCII representation of a time_t into a TextField?

Judy Koeppel

Somerville, MA

A: Use Objective-C's facility for categories to add a setDateValue: method to the TextField class. Create a new #import file called TextFieldAdditions.h that looks like this:


	@interface TextField(Additions)
	- setDateValue:(time_t)time;
	Place the definition for the Additions category in a file called TextFieldAdditions.m:
	#import "TextFieldAdditions.h"

	@implementation TextField(Additions)
	- setDateValue:(time_t)time
	        [self   setStringValue:asctime(localtime(&time))];
 	       return self;
Now you can send any TextField a message like this:

	[aTextField	setDateValue:timeval];
And have it look like this:
Tue Feb 4 11:17:28 1992
Simson L. Garfinkel is a senior editor at NeXTWORLD.