8

I would like to do the opposite of the following code:

RAC(self.activityIndicator, hidden) = RACObserve(self.playButton, selected);

When the play button is selected the activity indicator should be NOT hidden.

What is the best way to do this using ReactiveCocoa?

Onato
  • 9,916
  • 5
  • 46
  • 54

3 Answers3

29

There's a signal operator for this, -not.

RAC(self.activityIndicator, hidden) = [RACObserve(self.playButton, selected) not];
Dave Lee
  • 6,299
  • 1
  • 36
  • 36
4

map: is what you need.

RAC(self.activityIndicator, hidden) = [RACObserve(self.playButton, selected) map:^id(id value) {
    return @(![value boolValue]);
}];

This transforms the signal into another one based on what you return from the map function.

Lance
  • 8,872
  • 2
  • 36
  • 47
0

In newer versions of ReactiveCocoa/ReactiveSwift (v6.2.1) it will look like this:

var isButtonEnabled = MutableProperty<Bool>(true)

myImageView.reactive.isHidden <~ isButtonEnabled.negate()

Garnik
  • 423
  • 1
  • 6
  • 20