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:
#importNow you can send any TextField a message like this:#import @interface TextField(Additions) - setDateValue:(time_t)time; @end 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; } @end
[aTextField setDateValue:timeval];And have it look like this:
Tue Feb 4 11:17:28 1992Simson L. Garfinkel is a senior editor at NeXTWORLD.