标签:
// 定义一个Block Object,返回值:NSString;别名:intToString;参数:NSUInteger。 NSString* (^intToString)(NSUInteger) = ^(NSUInteger paramInteger){ NSString *result = [NSString stringWithFormat:@"%lu",(unsignedlong)paramInteger]; return result; };
// 调用我们定义的Block Ojbect NSString *string = intToString(10); NSLog(@"string = %@", string);
typedef NSString* (^IntToStringConverter)(NSUInteger paramInteger);
- (NSString *)convertIntToString:(NSUInteger)paramInteger usingBlockObject:(IntToStringConverter)paramBlockObject{ return paramBlockObject(paramInteger); }
NSString *result = [self convertIntToString:123 usingBlockObject:intToString]; NSLog(@"result = %@", result);
typedef NSString* (^IntToStringConverter)(NSUInteger paramInteger);
- (NSString *)convertIntToString:(NSUInteger)paramInteger usingBlockObject:(IntToStringConverter)paramBlockObject{ return paramBlockObject(paramInteger); }
- (void) doTheConversion{ IntToStringConverter inlineConverter = ^(NSUInteger paramInteger){ NSString *result = [NSString stringWithFormat:@"%lu", (unsignedlong)paramInteger]; return result; }; NSString *result = [self convertIntToString:123usingBlockObject:inlineConverter]; NSLog(@"result = %@", result); }
标签:
原文地址:http://www.cnblogs.com/weiboyuan/p/4195902.html