DefaultVehicleProvider

public class DefaultVehicleProvider : VehicleProvider

Provides a thread-safe implementation of the VehicleProvider.

Provides the option to update a vehicle or specified vehicle properties and to subscribe to property changes.

Important

This is a Public Preview API. It may be changed or removed at any time.

Initializer

  • Initializes default vehicle provider.

    Declaration

    Swift

    public init(vehicle: Vehicle = Car(combustionEngine: CombustionEngine()))

    Parameters

    vehicle

    The current vehicle to be provided. If not specified the default value is Car with CombustionEngine.

Public

  • Snapshot of the current vehicle state.

    Declaration

    Swift

    public var vehicleSnapshot: Vehicle { get }
  • Represents current vehicle state.

    Setting a different vehicle notifies observers of the latest vehicle state. If an observer is registered for multiple vehicle property updates and these properties are updated at the same time, the observer is only notified once.

    Setting the new vehicle is only expected to occur on the main queue.

    Declaration

    Swift

    public var vehicle: Vehicle { get set }
  • Registers a vehicle update observer for all vehicle property updates. The call is expected on the main queue.

    Throws

    Throws:VehicleError.alreadyRegisteredObserver upon adding the same observer more than once.

    Declaration

    Swift

    public func addObserver(_ observer: some VehicleUpdateObserver) throws

    Parameters

    observer

    The observer to be registered.

  • Registers a vehicle update observer for specific vehicle property updates. The call is expected on the main queue.

    Throws

    Throws:VehicleError.alreadyRegisteredObserver upon adding the same observer more than once.

    Declaration

    Swift

    public func addObserver(
        _ observer: some VehicleUpdateObserver,
        for trackedPropertyIDs: [PropertyID]
    ) throws

    Parameters

    observer

    The observer to be registered.

    trackedPropertyIDs

    Identifiers of vehicle properties whose changes will trigger the notification.

  • Removes a previously registered observer. The call is expected on the main queue.

    Declaration

    Swift

    public func removeObserver(_ observer: some VehicleUpdateObserver)

    Parameters

    observer

    The registered observer.

  • Updates the vehicle state with specified properties only.

    Throws

    VehicleError.invalidVehicleProperty, if the vehicle properties are not valid for the current vehicle type.

    Updating vehicle properties notifies observers of the latest vehicle state. If an observer is registered for multiple vehicle property updates and these properties are updated at the same time, the observer is only notified once.

    The call is expected on the main queue.

    Declaration

    Swift

    public func updateVehicleState(with properties: [VehicleProperty]) throws

    Parameters

    properties

    The vehicle properties to update.