Rac迭代

2018-01-25  本文已影响8人  我是小胡胡123

Rac迭代、绑定、Join
RACStream、RACSignal、RACSequence

1、RACSequence队列

typedef struct {
unsigned long state;
id __unsafe_unretained _Nullable * _Nullable itemsPtr;
unsigned long * _Nullable mutationsPtr;
unsigned long extra[5];
} NSFastEnumerationState;

@protocol NSFastEnumeration

//转换成C的数组

@end

RACStringSequence *sequence2=[@"12345" rac_sequence];

// head/tail countByEnumeratingWithState方式迭代
for (NSString *str in sequence2) {
NSLog(@"%@", str);
}
// 用nextObject的方式迭代

// head/ tail / nextObject

NSEnumerator *enumerator=sequence2.objectEnumerator;
NSString *next = enumerator.nextObject;
while(next!=nil) {
    NSLog(@"%@", next);
    next = enumerator.nextObject;
}

// A block used to evaluate head. This should be set to nil after _head has been
// initialized.
//
// This is marked strong instead of copy because of some bizarre block
// copying bug. See https://github.com/ReactiveCocoa/ReactiveCocoa/pull/506.
//
// The signature of this block varies based on the value of hasDependency:
//
// - If YES, this block is of type id (^)(id).
// - If NO, this block is of type id (^)(void).
//
// This property should only be accessed while synchronized on self.
@property (nonatomic, strong) id headBlock;

id (^block1) (void ) ;

id (^block2) (id ) ;

, @"-bind: block returned an object that is not a sequence: %@", current);
return nil;
} headBlock:^(id _) {
return current.head;
} tailBlock:^ id (id _) {
if (stop) return nil;
// current.tail 这里有一个迭代
//如果这里是RACEmptySequence
return [valuesSeq bind:bindBlock passingThroughValuesFromSequence:current.tail];
}];

sequence.name = self.name;
return sequence;

}

2、RACSignal

3、RACStream的私有方法

用在RacSignal的 CombineLatest方法, RACSequence没有此操作

上一篇 下一篇

猜你喜欢

热点阅读