首页 > 移动平台 > 详细

ios block使用

时间:2015-02-03 19:08:33      阅读:259      评论:0      收藏:0      [点我收藏+]
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;

@end

BlockTest.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使用

原文:http://www.cnblogs.com/joesen/p/4270461.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!