简体   繁体   English

反应性可可粉-然后在自定义信号与UI信号上

[英]Reactive Cocoa - then on custom signal vs UI signal

I'm starting to work with Reactive Cocoa so I've written a little test to see whether I understand then construct. 我开始使用活性可可粉,因此我编写了一个小测试以了解我是否理解然后构造。 The goal was to output text from a text field to the label only after some signal is sent. 目标是仅在发送某些信号后才将文本从文本字段输出到标签。 I've tried rac_signalForControlEvents(UIControlEvents.TouchUpInside) and VERY simple custom signal. 我已经尝试过rac_signalForControlEvents(UIControlEvents.TouchUpInside)和非常简单的自定义信号。 Former does not even call then closure while the latter does work as intended. 前者甚至不调用然后关闭,而后者确实按预期工作。 What is the problem here? 这里有什么问题?

func someSetupFunction()
{
#if true
    // Why does this doesn't work?

    button.rac_signalForControlEvents(UIControlEvents.TouchUpInside).then
        {
            let strongSelf = weakSelf
            return strongSelf?.textField.rac_textSignal()
        }.subscribeNext
        { object in
            let strongSelf = weakSelf
            strongSelf?.label.text = object as! String! + " - 0"
        }
#else
    // ... but this does?

    customSignal().then
        {
            let strongSelf = weakSelf
            return strongSelf?.textField.rac_textSignal()
        }.subscribeNext
        { object in
            let strongSelf = weakSelf
            strongSelf?.label.text = object as! String! + " - 1"
        }
#endif
}

func customSignal() -> RACSignal
{
    return RACSignal.createSignal
        { subscriber in
            subscriber.sendNext(nil)
            subscriber.sendCompleted()
            return nil
        }
}

From the docs for then : 从文档然后

Ignores all nexts from the receiver, waits for the receiver to complete, then subscribes to a new signal. 忽略接收方的所有下一个,等待接收方完成,然后订阅新信号。

button.rac_signalForControlEvents does not complete (at least not on a button tap), thats why nothing happens. button.rac_signalForControlEvents未完成(至少没有在单击按钮时完成),这就是为什么什么也没有发生的原因。

Original answer by iv-mexx can be found at https://github.com/ReactiveCocoa/ReactiveCocoa/issues/2671 iv-mexx的原始答案可以在https://github.com/ReactiveCocoa/ReactiveCocoa/issues/2671中找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与自定义信号的双向绑定,反应性可可无法正常工作 - Two way binding with custom signal with Reactive Cocoa not working as expected 反应性可可分裂信号而不重复代码? - Reactive Cocoa Splitting a signal without code duplication? 在Reactive Cocoa 4中点击UIButton获取信号 - Get Signal from tap on UIButton in Reactive Cocoa 4 使用Reactive Cocoa组合多个信号不起作用 - Combining multiple signal not working using Reactive Cocoa 如何等到任务完成后再返回信号,可可 - how to wait until the task is completed and then return a signal, reactive cocoa 如何绑定信号 <Bool, NoError> 在Reactive Cocoa 4中启用UIButton的属性 - How to bind Signal<Bool, NoError> to enabled property of UIButton in Reactive Cocoa 4 有什么方法可以将几个信号变成一个信号,而不是在可可粉中将它们弄平 - Are there any ways to make several signals into one signal instead of flatten them in Reactive Cocoa 反应性可可问题。如何等待多个RACSignal完成然后发送下一个信号 - Reactive cocoa issue.How to wait mutiple RACSignal completed then send a next signal iOS MVVM与可可,UITextField返回信号和条件:如何改进我的代码 - iOS MVVM with Reactive Cocoa, UITextField return signal and condition : how to improve my code 反应性文本字段信号不会在删除时触发 - Reactive textfield signal doesn't fire on delete
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM