BCXAction

Objective-C

@protocol BCXAction <NSObject>

Swift

protocol BCXAction : NSObjectProtocol

An action represents a unit of work that must be performed by the system. It usually encapsulate the data needed to perform a particular task at a later time. An example of an action is “mute the microphone of the device, during a phone call”. Once an action has been performed by the system, it is marked as completed and it will contain the result of the task carried out. However, if for any reasons the action could not be fulfilled, the action will be marked as completed and as faulted and an error will be provided in order to explain why the task has failed. Because actions might be performed at a later time after being created, or they might involve time consuming tasks the should be carried out in background, you usually want to be notified when the action has been fulfilled or has failed. For this purpose action objects provide callbacks where you can hook up and be called when an action has been completed.

  • A boolean flag specifying whether the action has been completed, or not. When an action is fulfilled o is faulted it’s marked as completed.

    Declaration

    Objective-C

    @property (nonatomic, readonly, getter=isCompleted) BOOL completed;

    Swift

    var isCompleted: Bool { get }
  • A boolean flag specifying whether the action could not be fulfilled because of an error.

    Declaration

    Objective-C

    @property (nonatomic, readonly, getter=isFaulted) BOOL faulted;

    Swift

    var isFaulted: Bool { get }
  • The result yield while performing the action, if any.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) id result;

    Swift

    var result: Any? { get }
  • The error occurred while performing the action, if any.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSError *error;

    Swift

    var error: Error? { get }
  • Fulfills the action with no result. Once the action is fulfilled, any continuation block attached, will be invoked.

    Declaration

    Objective-C

    - (void)fulfill;

    Swift

    func fulfill()
  • Fulfills the action with the result provided as argument. Once the action is fulfilled, any continuation block attached, will be invoked.

    Declaration

    Objective-C

    - (void)fulfillWithResult:(nullable id)result;

    Swift

    func fulfill(withResult result: Any?)

    Parameters

    result

    The result of the action

  • Fails the action specifying the error occurred. Once the action is faulted, any continuation block attached, will be invoked.

    Declaration

    Objective-C

    - (void)failWithError:(nonnull NSError *)error;

    Swift

    func failWithError(_ error: Error)

    Parameters

    error

    The error occurred.

  • Add the continuation block provided as argument. The block will be executed when the action is marked as completed, regardless of whether it was failed or fulfilled. If the continuation block is added to an action that has completed already, the block will be invoked immediately. The block will be invoked synchronously on the queue where the action completes, or on the queue where the block is added if the action has completed already.

    Declaration

    Objective-C

    - (void)continueWith:(nonnull void (^)(id<BCXAction> _Nonnull))block;

    Swift

    func `continue`(_ block: @escaping (BCXAction) -> Void)

    Parameters

    block

    The continuation block.

  • Add the continuation block provided as argument. The block will be executed when the action is marked as completed, regardless of whether it was failed or fulfilled. If the continuation block is added to an action that has completed already, the block will be invoked immediately. The block will be invoked asynchronously on the main queue.

    Declaration

    Objective-C

    - (void)continueOnMainQueueWith:(nonnull void (^)(id<BCXAction> _Nonnull))block;

    Swift

    func continueOnMainQueue(_ block: @escaping (BCXAction) -> Void)

    Parameters

    block

    The continuation block.

  • Add the continuation block provided as argument. The block will be executed when the action is marked as completed, regardless of whether it was failed or fulfilled. If the continuation block is added to an action that has completed already, the block will be invoked immediately. The block will be invoked asynchronously on the queue provided as argument.

    Declaration

    Objective-C

    - (void)continueOnQueue:(nonnull dispatch_queue_t)queue
                       with:(nonnull void (^)(id<BCXAction> _Nonnull))block;

    Swift

    func `continue`(on queue: DispatchQueue, with block: @escaping (BCXAction) -> Void)

    Parameters

    queue

    The dispatch queue where the block must be dispatched to.

    block

    The continuation block.