Receive a signal from a faucet on a UIButton in Cocoa 4 reagent

How can I create a Signaltap on UIButton?

So far, I have been trying to use a goal / action , but thought there might be an easier way.

An article by Colin Eberhardt states that they Signalsare suitable for user interface actions. But when I tried to set the goal / action, I needed to create CocoaAction, ultimately, initialized with SignalProducer.

I want a little Signalthat emits events nextevery time the user clicks. Then I want to convert this Signal to read from UITextFieldsand use these values ​​to use them in my application.

+4
source share
2 answers

Using the convenient functions from this gist by @NachoSoto, I was able to achieve this simply with signalForControlEvents(UIControlEvents.TouchUpInside):

self.startButton
      .signalForControlEvents(UIControlEvents.TouchUpInside)
      .map { _ in (self.name1TextField.text!, self.name2TextField.text!)}
      .observe { event in
          if let names = event.value {
              print("received names \(names)")
          }
       }
+5
source
 self.startButton
     .rac_signalForControlEvents(UIControlEvents.TouchUpInside)
     .subscribeNext { event in
         if let names = event.value {
            print("received names \(names)")
         }
     }
+4
source

Source: https://habr.com/ru/post/1619390/


All Articles