[self rac_liftSelector:(SEL) withSignalsFromArray:(NSArray *)];
使用场景:当有多个任务执行时,全部执行完毕才能执行其他操作,注意方法的参数必须跟后面信号一一对应不然就会报错,方法的参数就是每个信号发送的数据.
- 代码:
//1. rac_lift调用
RACSignal *signal1 = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
NSLog(@"任务1");
[subscriber sendNext:@"数据1"];
return nil;
}];
RACSignal *signal2 = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
NSLog(@"任务2");
[subscriber sendNext:@"数据2"];
return nil;
}];
[self rac_liftSelector:@selector(updateUIWithData1:data2:) withSignalsFromArray:@[signal1,signal2]];
//2. 任务完成后方法
- (void)updateUIWithData1:(NSString *)data1 data2:(NSString *)data2 {
NSLog(@"data1:%@data2:%@",data1,data2);
}
RAC常见的宏.
- 1. RAC(<#TARGET, ...#>) 用来给某个对象的某个属性绑定信号,只要产生信号内容就会把内容给属性赋值.
RAC(<#TARGET, ...#>)
//只要_textField值改变前面label中text就会改变为相应内容
RAC(_label,text) = _textField.rac_textSignal;
- 2. RACObserve(<#TARGET#>, <#KEYPATH#>)监听对象的属性:
RACObserve(<#TARGET#>, <#KEYPATH#>)
[RACObserve(self.reaVIew, frame) subscribeNext:^(id x) {
NSLog(@"对象属性一改变就会被调用");
}];
- 防止blcok循环引用:
@weakify(self);
@strongify(self);
-
封装集合
RACTuplePack(<#...#>):把数据包装成元组,返回值为元组.
RACTupleUnpack(<#...#>):把元组解包成对应数据.
-
封装集合
//RACTuplePack
RACTuple *tuple = RACTuplePack(@"12",@"3232");
NSLog(@"%@",tuple[0]);
//RACTupleUnpack
RACTupleUnpack(NSString *str1,NSString *str2) = tuple;
NSLog(@"%@--%@",str1,str2);
网友评论