fork download
  1. #import <Foundation/Foundation.h>
  2.  
  3. @interface NSNumber (MathExt)
  4.  
  5. - (NSNumber *)add:(NSNumber *)otherNumber;
  6.  
  7. @end
  8.  
  9. @implementation NSNumber (MathExt)
  10.  
  11. - (NSNumber *)add:(NSNumber *)otherNumber
  12. {
  13. double left = [self doubleValue];
  14. double right = [otherNumber doubleValue];
  15.  
  16. return [NSNumber numberWithDouble:left+right];
  17. }
  18.  
  19. @end
  20.  
  21. int main()
  22. {
  23. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  24.  
  25. NSNumber *one = [NSNumber numberWithDouble:1.2];
  26. NSNumber *two = [NSNumber numberWithInt:2];
  27. NSNumber *three = [NSNumber numberWithBool:YES];
  28. NSNumber *four = [NSNumber numberWithChar:'a'];
  29.  
  30. NSNumber *result = [one add:two];
  31. result = [result add:three];
  32. result = [result add:four];
  33.  
  34. NSLog(@"%f", [result doubleValue]);
  35.  
  36. [pool release];
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.03s 10832KB
stdin
Standard input is empty
stdout

Standard output is empty