double(^g)(double, double) = ^(double a, double b){
double c = a +b ;
return c;
};
^(double a, double b) // the caret represents a block literal. This block takes two double parameters. Note we don't have to explicitly specify the return type{ double c = a + b; return c; //}vtypedef double(^BinaryOpBlock_t)(double, double);BinaryOpBlock_t operation_creator(int op){ if (op == 0) return ^(double x, double y) { return x + y; }; // addition block if (op == 1) return ^(double x, double y) { return x * y; }; // multiplication block// ... etc.}int main(){ BinaryOpBlock_t sum = operation_creator(0); // option '0' represents addition NSLog(@"sum of 5.5 and 1.3 is %f", sum(5.5, 1.3)); NSLog(@"product of 3.3 and 1.0 is %f", operation_creator(1)(3.3, 1.0)); // cool, we've composed the function invocation and the block invocation!}
typedef NS_ENUM(NSUInteger, MCSwipeTableViewCellState){
MCSwipeTableViewCellStateNone = 0,
MCSwipeTableViewCellState1,
MCSwipeTableViewCellState2,
MCSwipeTableViewCellState3,
MCSwipeTableViewCellState4
};
コメント
コメントを投稿