arkilis
5/9/2017 - 10:36 PM

NSNumber+CalculateChain2

NSNumber+CalculateChain2


// NSNumber+CalculateChain2.h
#import <Foundation/Foundation.h>

@interface NSNumber (CalculateChain2)

-(NSNumber*(^)(float))add;
-(NSNumber*(^)(float))minus;
-(NSNumber*(^)(float))multiply;
-(NSNumber*(^)(float))divide;

@end
  
  
// NSNumber+CalculateChain2.m
#import "NSNumber+CalculateChain2.h"

@implementation NSNumber (CalculateChain2)


-(NSNumber*(^)(float))add{
    return ^NSNumber *(float value){
        return [NSNumber numberWithFloat:([self floatValue] + value)];
    };
}


-(NSNumber*(^)(float))minus{
    return ^NSNumber *(float value){
        return [NSNumber numberWithFloat:([self floatValue] - value)];
    };
}


-(NSNumber*(^)(float))multiply{
    return ^NSNumber *(float value){
        return [NSNumber numberWithFloat:([self floatValue] * value)];
    };
}


-(NSNumber*(^)(float))divide{
    return ^NSNumber *(float value){
        return [NSNumber numberWithFloat:([self floatValue] / value)];
    };
}


@end