RAC中有幾種常用的集合類
RACTuple
- 元組類净响,也相當(dāng)于RAC中的數(shù)組
- 常用創(chuàng)建方式
+ (instancetype)tupleWithObjectsFromArray:(NSArray *)array;
+ (instancetype)tupleWithObjects:(id)object, ... NS_REQUIRES_NIL_TERMINATION;
……
- 案例
RACTuple *tuple = [RACTuple tupleWithObjects:@"aaa", @"bbb", @123, nil];
NSString *str = tuple[0];
NSLog(@"%@", str);
RACSequence
- 代替數(shù)組字典辛辨,用于快速遍歷邓梅,常用與數(shù)組/字典轉(zhuǎn)模型
//定義一個(gè)數(shù)組
NSArray *arr = @[@"a", @"b", @"c"];
//RAC集合
RACSequence *req = arr.rac_sequence;
//遍歷
RACSignal *signal = req.signal;
[signal subscribeNext:^(id _Nullable x) {
NSLog(@"%@", x);
}];
//簡寫
[arr.rac_sequence.signal subscribeNext:^(id _Nullable x) {
NSLog(@"%@", x);
}];
//字典時(shí)蚀之,返回的是元組
NSDictionary *dic = @{@"name":@"abc", @"age":@18};
[dic.rac_sequence.signal subscribeNext:^(RACTuple *x) {
//解包RACTuple
RACTupleUnpack(NSString *key, NSString *value) = x;
NSLog(@"%@:%@", key, value);
}];