With ReactiveCocoa bind to inverse of BOOL
Asked Answered
K

3

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?

Krishna answered 25/1, 2014 at 18:7 Comment(0)
O
29

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

RAC(self.activityIndicator, hidden) = [RACObserve(self.playButton, selected) not];
Orville answered 25/1, 2014 at 19:22 Comment(0)
W
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.

Wherefrom answered 25/1, 2014 at 18:18 Comment(0)
P
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()

Permenter answered 9/4, 2020 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.