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

  • Setting a different vehicle notifies observers of the latest vehicle state and updated properties. To update only specific properties of the current vehicle, see TomTomSDKVehicle/VehicleProvider/updateVehicle(with:). All vehicle updates must be done on the main queue.

    Declaration

    Swift

    public var vehicle: Vehicle { get set }
  • Updates the specific properties of the current vehicle.

    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 and updated properties. To set a new vehicle, use TomTomSDKVehicle/VehicleProvider/vehicle. All vehicle updates must be done on the main queue.

    Declaration

    Swift

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

    Parameters

    properties

    The vehicle properties to update.

  • Adds a TomTomSDKVehicle/VehicleUpdateObserver to DefaultVehicleProvider. The call is expected on the main queue. The system keeps a weak reference to the observer.

    Declaration

    Swift

    public func addObserver(_ observer: some VehicleUpdateObserver)

    Parameters

    observer

    A class that can handle vehicle update events.

  • Removes the TomTomSDKVehicle/VehicleUpdateObserver from DefaultVehicleProvider. There is no need to unregister the observer. If the observer is not removed, the system will clean up when the next event is posted. The call is expected on the main queue. Do not call this method from the deinitializer of the observer, unless you are certain that the observer will be destroyed on the main queue.

    Declaration

    Swift

    public func removeObserver(_ observer: some VehicleUpdateObserver)

    Parameters

    observer

    A class that can handle vehicle update events.