gpt4 book ai didi

ios - RACSequence 和 RACSignal 有什么区别

转载 作者:可可西里 更新时间:2023-11-01 05:03:11 32 4
gpt4 key购买 nike

也许我完全忽略了这一点,但根据 ReactiveCocoa on their types 上的文档, RAC序列是信号。

但是。我看到你有这样的代码的例子:

RACSignal *letters = [@"A B C D E F G H I" componentsSeparatedByString:@" "].rac_sequence.signal;

// Outputs: A B C D E F G H I
[letters subscribeNext:^(NSString *x) {
NSLog(@"%@", x);
}];

还有

RACSequence *letters = [@"A B C D E F G H I" componentsSeparatedByString:@" "].rac_sequence;

// Contains: AA BB CC DD EE FF GG HH II
RACSequence *mapped = [letters map:^(NSString *value) {
return [value stringByAppendingString:value];
}];

很多例子都有 RACSequence 和 RACSignal。 rac_sequence.signal 或仅订阅信号本身有什么区别?

最佳答案

一个是拉驱动 (RACSequence),另一个是推驱动 (RACSignal)。来自 here :

Push-driven means that values for the signal are not defined at the moment of signal creation and may become available at a later time (for example, as a result from network request, or any user input). Pull-driven means that values in the sequence are defined at the moment of signal creation and we can query values from the stream one-by-one.

在您的例子中,您使 RACSignal 成为拉动驱动,因为您已经拥有它的值。

关于ios - RACSequence 和 RACSignal 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28952900/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com