Inherits from NSObject
Declared in RACCommand.h

Overview

A command is a signal triggered in response to some action, typically UI-related.

Tasks

Other Methods

Unavailable Methods

Properties

allowsConcurrentExecution

Whether the command allows multiple executions to proceed concurrently.

@property (atomic, assign) BOOL allowsConcurrentExecution

Discussion

Whether the command allows multiple executions to proceed concurrently.

The default value for this property is NO.

Declared In

RACCommand.h

canExecute

@property (atomic, readonly) BOOL canExecute

enabled

A signal of whether this command is able to execute.

@property (nonatomic, strong, readonly) RACSignal *enabled

Discussion

A signal of whether this command is able to execute.

This will send NO if:

Once the above conditions are no longer met, the signal will send YES.

This signal will send its current value upon subscription, and then all future values on the main thread.

Declared In

RACCommand.h

errors

Forwards any errors that occur within signals returned by execute:.

@property (nonatomic, strong, readonly) RACSignal *errors

Discussion

Forwards any errors that occur within signals returned by execute:.

When an error occurs on a signal returned from execute:, this signal will send the associated NSError value as a next event (since an error event would terminate the stream).

After subscription, this signal will send all future errors on the main thread.

Declared In

RACCommand.h

executing

A signal of whether this command is currently executing.

@property (nonatomic, strong, readonly) RACSignal *executing

Discussion

A signal of whether this command is currently executing.

This will send YES whenever execute: is invoked and the created signal has not yet terminated. Once all executions have terminated, executing will send NO.

This signal will send its current value upon subscription, and then all future values on the main thread.

Declared In

RACCommand.h

executionSignals

A signal of the signals returned by successful invocations of execute: (i.e., while the receiver is enabled).

@property (nonatomic, strong, readonly) RACSignal *executionSignals

Discussion

A signal of the signals returned by successful invocations of execute: (i.e., while the receiver is enabled).

Errors will be automatically caught upon the inner signals, and sent upon errors instead. If you want to receive inner errors, use -execute: or [RACSignal materialize].

Only executions that begin after subscription will be sent upon this signal. All inner signals will arrive upon the main thread.

Declared In

RACCommand.h

Class Methods

command

+ (instancetype)command

commandWithCanExecuteSignal:

+ (instancetype)commandWithCanExecuteSignal:(RACSignal *)canExecuteSignal

Instance Methods

addSignalBlock:

- (RACSignal *)addSignalBlock:(RACSignal *( ^ ) ( id value ))signalBlock

execute:

If the receiver is enabled, this method will:

- (RACSignal *)execute:(id)input

Discussion

If the receiver is enabled, this method will:

  1. Invoke the signalBlock given at the time of initialization.
  2. Multicast the returned signal to a RACReplaySubject.
  3. Send the multicasted signal on executionSignals.
  4. Subscribe (connect) to the original signal on the main thread.

input - The input value to pass to the receiver’s signalBlock. This may be nil.

Returns the multicasted signal, after subscription. If the receiver is not enabled, returns a signal that will send an error with code RACCommandErrorNotEnabled.

Declared In

RACCommand.h

initWithCanExecuteSignal:

- (id)initWithCanExecuteSignal:(RACSignal *)canExecuteSignal

initWithEnabled:signalBlock:

Initializes a command that is conditionally enabled.

- (id)initWithEnabled:(RACSignal *)enabledSignal signalBlock:(RACSignal *( ^ ) ( id input ))signalBlock

Discussion

Initializes a command that is conditionally enabled.

This is the designated initializer for this class.

enabledSignal - A signal of BOOLs which indicate whether the command should be enabled. enabled will be based on the latest value sent from this signal. Before any values are sent, enabled will default to YES. This argument may be nil. signalBlock - A block which will map each input value (passed to execute:) to a signal of work. The returned signal will be multicasted to a replay subject, sent on executionSignals, then subscribed to synchronously. Neither the block nor the returned signal may be nil.

Declared In

RACCommand.h

initWithSignalBlock:

Invokes -initWithSignalBlock:enabled: with a nil enabledSignal.

- (id)initWithSignalBlock:(RACSignal *( ^ ) ( id input ))signalBlock

Discussion

Invokes -initWithSignalBlock:enabled: with a nil enabledSignal.

Declared In

RACCommand.h