This is TestObject.m in view mode; [Download] [Up]
#import "TestObject.h"
@implementation TestObject
+ objectWithString:(NSString *)string
{
return [[[self alloc] initWithString:string] autorelease];
}
- initWithString:(NSString *)string
{
NSCharacterSet *semicolonSet;
NSScanner *scanner;
int number;
[super init];
scanner = [NSScanner scannerWithString:string];
semicolonSet = [NSCharacterSet characterSetWithCharactersInString:@";"];
if([scanner scanInt:&number])
theNumber = [[NSNumber numberWithInt:number] retain];
else
theNumber = [[NSNumber numberWithInt:0] retain];
if(![scanner scanUpToCharactersFromSet:semicolonSet intoString:&theString])
theString = [[NSString stringWithCString:"default"] retain];
else
[theString retain];
return self;
}
- (void)dealloc
{
[theNumber release];
[theString release];
return [super dealloc];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@-%@", [theNumber description], [theString description]];
}
- (NSComparisonResult)compare:(TestObject *)otherObject
{
if(!otherObject)
return NSOrderedDescending;
return [(NSNumber *)theNumber compare:otherObject->theNumber];
}
@endThese are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.