一 方法的实现
#import <Foundation/Foundation.h>
@interface RJBlockTool : NSObject
//计算
+ (RJBlockTool *)makeMethodCalculator:(CGFloat(^)(CGFloat result))block;
- (BOOL)isEqualResult:(BOOL (^)(CGFloat result))block;
@end
#import "RJBlockTool.h"
@interface RJBlockTool()
//1 计算的结果
@property(nonatomic,assign) CGFloat resultCalculator;
@end
@implementation RJBlockTool
+(RJBlockTool *)makeMethodCalculator:(CGFloat (^)(CGFloat))block{
if (block) {
RJBlockTool *tool = [[RJBlockTool alloc] init];
tool.resultCalculator = block(tool.resultCalculator);
return tool;
}
return nil;
}
-(BOOL)isEqualResult:(BOOL (^)(CGFloat))block{
return block(self.resultCalculator);
}
@end
二 使用
NSLog(@"isEqualResult---%d",[[RJBlockTool makeMethodCalculator:^CGFloat(CGFloat result) {
result += 100;result /= 10;return result;
}] isEqualResult:^BOOL(CGFloat result) {
return result==10;
}]);
isEqualResult---1
网友评论