home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / NSObjectAdditions.m < prev    next >
Encoding:
Text File  |  1996-08-23  |  1.0 KB  |  42 lines

  1. /*
  2.         Copyright (c) 1996, NeXT Software, Inc.
  3.         All rights reserved.
  4.  
  5.         You may freely copy, distribute and reuse the code in this example.
  6.         NeXT disclaims any warranty of any kind, expressed or implied,
  7.         as to its fitness for any particular use.
  8. */
  9. #import <BusinessLogic/NSObjectAdditions.h>
  10. #import <EOControl/EOControl.h>
  11.  
  12. @implementation NSObject(NSObjectAdditions)
  13.  
  14. - (NSString *)className
  15. {
  16.    return NSStringFromClass([self class]);
  17. }
  18.  
  19. @end
  20.  
  21. @implementation NSArray(NSDecimalNumberAdditions)
  22.  
  23. - (NSDecimalNumber *)sumArrayWithKey:(NSString *)key
  24. {
  25.     NSDecimal result = [[NSDecimalNumber zero] decimalValue];
  26.     int i = [self count];
  27.     
  28.     while( i-- ) {
  29.         NSDecimalNumber *n = [[self objectAtIndex:i] valueForKeyPath:key];
  30.         
  31.         if(n) {
  32.             NSDecimal num;
  33.             num = [n decimalValue];
  34.             (void)NSDecimalAdd(&result, &result,  &num, NSRoundBankers);          
  35.         }
  36.     }
  37.     return [NSDecimalNumber decimalNumberWithDecimal:result];
  38. }
  39.  
  40. @end
  41.  
  42.