ios – ReactiveCocoa将SignalProducers合二为一

栏目: Objective-C · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/32210564/reactivecocoa-combine-signalproducers-into-one
我正在使用Reactive Cocoa

,我有几个SignalProducers

let center = NSNotificationCenter.defaultCenter()
let signalProducer1 = center.rac_notification(name: notificationName1, object: nil)
let signalProducer2 = center.rac_notification(name: notificationName2, object: nil)
let signalProducer3 = center.rac_notification(name: notificationName3, object: nil)

我想将它们组合成一个信号产生器,只要其中一个产生信号就会产生信号.

起初,combineLatest功能看起来是一个很好的解决方案

let combinedProducer = combineLatest(signalProducer1, signalProducer2, signalProducer3)

但是,根据 this article ,生成的生产者只有在三者都产生信号时才产生第一个信号.

This interactive diagram 显示了我想要的内容,因此我想使用.Merge FlatteningStrategy的flatten函数.但是,我很难搞清楚实现这一目的的语法.

您可以按如下方式实现:
let merged = SignalProducer(values: [ signalProducer1, signalProducer2, signalProducer3 ])
    |> flatten(.Merge)

翻译自:https://stackoverflow.com/questions/32210564/reactivecocoa-combine-signalproducers-into-one


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

High Performance Python

High Performance Python

Andrew Lewis / O'Reilly Media, Inc. / 2010-09-15 / USD 34.99

Chapter 1. Introduction Section 1.1. The High Performance Buzz-word Chapter 2. The Theory of Computation Section 2.1. Introduction Section 2.2. Problems Section 2.3. Models of Computati......一起来看看 《High Performance Python》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

SHA 加密
SHA 加密

SHA 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器