FirebaseFirestore Framework Reference

Constant

public struct Constant : Expression, BridgeWrapper, @unchecked Sendable

A Constant is an Expression that represents a fixed, literal value within a Firestore pipeline.

Constants are used to introduce literal values into a query, which can be useful for:

  • Comparing a field to a specific value in a where clause.
  • Adding new fields with fixed values using addFields.
  • Providing literal arguments to functions like sum or average.

Example of using a Constant to add a new field:

// Add a new field "source" with the value "manual" to each document
firestore.pipeline()
  .collection("entries")
  .addFields([
    Constant("manual").as("source")
  ])
  • Creates a new Constant expression from an integer literal.

    Declaration

    Swift

    public init(_ value: Int)

    Parameters

    value

    The integer value.

  • Creates a new Constant expression from a double-precision floating-point literal.

    Declaration

    Swift

    public init(_ value: Double)

    Parameters

    value

    The double value.

  • Creates a new Constant expression from a string literal.

    Declaration

    Swift

    public init(_ value: String)

    Parameters

    value

    The string value.

  • Creates a new Constant expression from a boolean literal.

    Declaration

    Swift

    public init(_ value: Bool)

    Parameters

    value

    The boolean value.

  • Creates a new Constant expression from a Data (bytes) literal.

    Declaration

    Swift

    public init(_ value: Data)

    Parameters

    value

    The Data value.

  • Creates a new Constant expression from a GeoPoint literal.

    Declaration

    Swift

    public init(_ value: GeoPoint)

    Parameters

    value

    The GeoPoint value.

  • Creates a new Constant expression from a Timestamp literal.

    Declaration

    Swift

    public init(_ value: Timestamp)

    Parameters

    value

    The Timestamp value.

  • Creates a new Constant expression from a Date literal.

    The Date will be converted to a Timestamp internally.

    Declaration

    Swift

    public init(_ value: Date)

    Parameters

    value

    The Date value.

  • Creates a new Constant expression from a DocumentReference literal.

    Declaration

    Swift

    public init(_ value: DocumentReference)

    Parameters

    value

    The DocumentReference value.

  • Creates a new Constant expression from a VectorValue literal.

    Declaration

    Swift

    public init(_ value: VectorValue)

    Parameters

    value

    The VectorValue value.

  • nil

    A Constant representing a nil value.

    Declaration

    Swift

    public static let `nil`: Constant