map: 用于普通信号,信号发出普通值
RACSignal *subA = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
[subscriber sendNext:@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",]];
return nil;
}];
RACSignal *subB = [subA map:^id _Nullable(NSArray *_Nullable tempArr) {
// tempArr:源信号的内容
// 返回值,就是处理源信号的内容,在这里直接返回了
return tempArr;
}];
[subB subscribeNext:^(id _Nullable x) {
NSLog(@"(map)映射结果:%@",x);
/**
map)映射结果:(
1,
2,
3,
4,
5,
6,
7,
8
)
*/
}];
flattenMap:信号中信号,signalOfSignals
RACSignal *subA = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
[subscriber sendNext:@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",]];
return nil;
}];
[[subA flattenMap:^__kindof RACSignal * _Nullable(id _Nullable value) {
// value:源信号的内容
value = [NSString stringWithFormat:@"####%@",value];
// 返回值:信号,把处理完的值包装成信号返回出去(信号中的信号)
return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
[subscriber sendNext:value];
return nil;
}];
}] subscribeNext:^(id _Nullable x) {// 订阅
// x:绑定信号的值
NSLog(@"订阅的值:%@",x);
//输出的结果
/*订阅的值:####(
1,
2,
3,
4,
5,
6,
7,
8
)
*/
}];
FlatternMap与Map的区别:
欢迎大佬儿来指正纠错,共同学习
网友评论