([NSArray -lastObject]): Don't assert count; just return nil if it's

empty.
([NSMutableArray -removeLastObject]): Don't assert count; raise
NSRangeError if it's empty.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1314 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mccallum 1996-03-30 23:00:27 +00:00
parent 336e25cf9f
commit 00e53dbf51

View file

@ -294,8 +294,9 @@ static Class NSMutableArray_concrete_class;
- lastObject - lastObject
{ {
int count = [self count]; int count = [self count];
assert(count); /* xxx should raise an NSException instead */ if (count == 0)
return [self objectAtIndex:count-1]; return nil;
return [self objectAtIndex: count-1];
} }
- (void) makeObjectsPerform: (SEL)aSelector - (void) makeObjectsPerform: (SEL)aSelector
@ -495,7 +496,9 @@ static Class NSMutableArray_concrete_class;
- (void) removeLastObject - (void) removeLastObject
{ {
int count = [self count]; int count = [self count];
assert(count); /* xxx should raise an NSException instead */ if (count == 0)
[NSException raise: NSRangeException
format: @"Trying to remove from an empty array."];
[self removeObjectAtIndex:count-1]; [self removeObjectAtIndex:count-1];
} }