DataHandler.h
@interfaceDataHandler :NSObject
#warning第一步
//声明方法在方法中封装block
-(void)sendNumber:(NSInteger)num
Block:(void(^)(NSString* string))block;
+(void)sendNumber:(NSInteger)num
Block:(void(^)(NSString* string))block;
(2)
-(void)appendString:(NSString*)string
Block:(void(^)(NSString* str))block;
+(void)separateString:(NSString* )string
Block:(void(^)(NSArray* array))block;
@end
DataHandler.m
(1)
@implementationDataHandler
#warning第二步
-(void)sendNumber:(NSInteger)num Block:(void(^)(NSString*))block{
NSString* string = [NSStringstringWithFormat:@"%ld",num];
block(string);
}
+(void)sendNumber:(NSInteger)num Block:(void(^)(NSString*))block{
NSString* string = [NSStringstringWithFormat:@"%ld",num];
block(string);
}
(2)
DataHandler2* dataHandler2 = [[DataHandler2alloc]init];
[dataHandler2appendString:@"99999"Block:^(NSString*str) {
self.textField.text= str;
}];
[DataHandler2separateString:@"9396@qq.com"Block:^(NSArray*array) {
NSLog(@"%@",array);
}];
@end
OneViewController.m
#warning第三步-- (-)号方法
DataHandler* dataHandler = [[DataHandleralloc]init];
[dataHandlersendNumber:10086
Block:^(NSString*string) {
self.label.text= string;
}];
OneViewController.m
#warning第三步-- (+)号方法
[DataHandlersendNumber:100000Block:^(NSString*string) {
self.textField.text=string;
}];