Tag Archives: RACCommand

Using RACCommand and creating custom RACSignals in Objective C

To bind some action to the button click one can use just a custom RACSignal. But then you have to add three more things in every case:
1. Disable button, while action is performing;
2. Show, that action is in progress;
3. Disable button, if input is incorrect and button should not be able to be tapped.

Instead, if you use RACCommand, you get all these things in a box.

Let’s say, we want to bind RACCommand verifyPhoneCommand to a button. We can create a command in a lazy property in a ViewModel:

Here phoneValidSignal is this signal, that is formed by observing a phone variable:

We pass a RACSignal verifyPhone to the RACCommand to do a job:

This is how we bind a RACCommand to a button:

To track execution of a RACCommand and show an activity indicator we can use executing property:

If errors happen during RACCommand execution we can process those errors: