Created
March 13, 2013 10:49
-
-
Save vikingosegundo/5151033 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <objc/runtime.h> | |
@interface MyDecimalNumber : NSDecimalNumber | |
@end | |
@implementation MyDecimalNumber | |
-(NSDecimal)decimalValue | |
{ | |
NSLog(@"%@ %@", NSStringFromSelector(_cmd), self); | |
return [super decimalValue]; | |
} | |
@end | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
short exp = -15; | |
NSArray *numbers = @[ [NSDecimalNumber decimalNumberWithMantissa:1 exponent:exp isNegative:NO], | |
[NSDecimalNumber decimalNumberWithMantissa:2 exponent:exp isNegative:NO], | |
[NSDecimalNumber decimalNumberWithMantissa:3 exponent:exp isNegative:NO]]; | |
[numbers enumerateObjectsUsingBlock:^(NSDecimalNumber *obj, NSUInteger idx, BOOL *stop) { | |
object_setClass(obj, [MyDecimalNumber class]); | |
}]; | |
NSDecimalNumber *sum = [numbers valueForKeyPath:@"@sum.self"]; | |
NSLog(@"%@", sum); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment