标签:
最近一直在搞项目,突然发觉用block特别是只掉一次的时候比代理好用多了,废话不多说block遍历数组
正序排序
NSArray *orginKeys = [[orginDictM1 allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj1 compare:obj2 options:NSNumericSearch];
}];
下面说一下当参数传递
- (instancetype)initWithView:(UIView *)view completion:(void(^)(OrderPay *order, NSDictionary *result, BOOL success))completion{
if (self = [super init]) {
completion(self, nil, YES);
}
return self;
}
如果是在这个方法里执行就可以直接调用block,
但是如果要在别的函数里调用这个block呢,让我搞了半天才知道,要引用一下,但是想到引用用什么好呢,这又让我困惑了
typedef void(^OrderBlock)(OrderPay *order, NSDictionary *result, BOOL success);
@property (nonatomic, copy) OrderBlock orderBlock;
- (instancetype)initWithView:(UIView *)view completion:(void(^)(OrderPay *order, NSDictionary *result, BOOL success))completion{
if (self = [super init]) {
self.orderBlock = completion;
}
return self;
}
这样就好了,如果方法不在本函数里面执行一定要引用一下,到你用的函数里面执行就可以了
标签:
原文地址:http://www.cnblogs.com/dream999/p/4489095.html