一,tuple,可以装任何对象,没有顺序,取值用[];
RACTuple *tuple = [RACTuple tupleWithObjects:@1,@"zhang",@78, nil];
NSLog(@"%@",tuple[1]);=
二,RACSequenceb遍历数组和字典
NSArray *array = @[@"zhang",@2, @8,@"jack"];
RACSequence *sequence = array.rac_sequence;
[sequence.signal subscribeNext:^(id x) {
//NSLog(@"内部会自动遍历数组");
//NSLog(@"%@",x);
}];
NSDictionary *dic = @{
@"name": @"zhangdanfeng",
@"age":@20,
@"height":@1.69,
};
[dic.rac_sequence.signal subscribeNext:^(id x) {
//返回值x是元组
//1,取出元组元素方法一:
NSLog(@"%@--%@",x[0],x[1]);
//2,取出元组方法二:(宏)
RACTupleUnpack(NSString *key, NSString *value) = x;
NSLog(@"%@---%@",key, value);
}];
三,字典转模型初级用法
NSMutableArray *flags = [NSMutableArray array];
NSArray *flagsArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"flags.plist" ofType:nil]] ;
[flagsArray.rac_sequence.signal subscribeNext:^(NSDictionary *x) {//x其实是字典
//需要注意的是,这里面的操作都是异步操作
IMFlag *flag = [IMFlag flagWithDict:x];
//之后创建一个数组并把flag模型放入数组中即可
[flags addObject:flag];
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"----%@",flags);
});
四,字典转模型高级用法:(直接用sequence映射map)
NSArray *resultArr = [[flagsArray.rac_sequence map:^id(NSDictionary *value) {
//value是遍历数组中的内容,这里也就是字典
return [IMFlag flagWithDict:value];
}] array];
NSLog(@"%@",resultArr);