首页 > 代码库 > ios block使用

ios block使用

BlockTest.h#import <Foundation/Foundation.h>typedef void (^didFinishBlock)(NSString *str);typedef void (^didFailBlock)(NSString *str);@interface BlockTest : NSObject+(void)justForTest:(NSString *)string finishBlock:(didFinishBlock)finishBlock failBlock:(didFailBlock)failBlock;@endBlockTest.m#import "BlockTest.h"@implementation BlockTest+(void)justForTest:(NSString *)string finishBlock:(didFinishBlock)finishBlock failBlock:(didFailBlock)failBlock{    if ([string isEqualToString:@"test"]) {         finishBlock(string);    }    else    {        failBlock(@"参数错误");    }   }@end// 使用 [BlockTest justForTest:@"testt" finishBlock:^(NSString *str) {       NSLog(@"%@",str);   } failBlock:^(NSString *str) {       NSLog(@"%@",str);   }];

 

ios block使用