I'm starting to work with Reactive Cocoa so I've written a little test to see whether I understand 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. Former does not even call 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.
Original answer by iv-mexx can be found at https://github.com/ReactiveCocoa/ReactiveCocoa/issues/2671
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.