BranchConditionable

@MainActor
public protocol BranchConditionable<ContentType>

A protocol that defines a condition used to select a branch path in an ActionBranch step.

When an ActionBranch runs, it evaluates each BranchConditionable condition in order by calling their evaluate(content:) method and selects the first case whose condition returns true. This protocol also provides an implementation of negated() so that a the same condition can be used in the inverse sense (i.e. “is online” vs. “is offline”).

Implement this protocol to define reusable, named conditions:

struct HasImagesCondition: BranchConditionable {
    func evaluate(content: AppContent?) -> Bool {
        guard case .images(let images) = content else { return false }
        return !images.isEmpty
    }
}
  • The content type this condition evaluates.

    Declaration

    Swift

    associatedtype ContentType : ContentTypeable
  • Evaluates the condition against the current content. There are a few simple conditions provided with Destinations such as BooleanCondition, AllSatisfyCondition, and AnySatisfyCondition, but you can implement this protocol to provide your own custom condition logic here.

    Declaration

    Swift

    @MainActor
    func evaluate(content: ContentType?) -> Bool

    Parameters

    content

    The content value forwarded to this branch step by the preceding conduit.

    Return Value

    true if this condition’s branch path should be selected; false otherwise.

  • negated() Default implementation

    A chainable method that provides a logical inverse of this condition that returns the opposite evaluation. For instance, if you have an IsOnlineCondition and chain this method, it would functionally act as an IsOfflineCondition.

    Use .negated() to reuse an existing condition type in its opposite sense, avoiding a separate type with duplicated evaluation logic.

    .branch(when: IsUserLoggedInCondition().negated(), action: showLoginUI)
    

    Default Implementation

    Declaration

    Swift

    @MainActor
    func negated() -> NegatedCondition<ContentType>

    Return Value

    A NegatedCondition that passes whenever this condition would not, and vice versa.