DefaultVehicleProvider
public class DefaultVehicleProvider : VehicleProvider
Provides a thread-safe implementation of the VehicleProvider.
Provides option to update vehicle or specified vehicle parameters only and subscribe to parameter changes.
Important
This is a Public Preview API. It may be changed or removed at any time.-
Initializes default vehicle provider.
Declaration
Swift
public init(vehicle: Vehicle = Car(combustionEngine: CombustionEngine()))Parameters
vehicleThe current vehicle to be provided. If not specified the default value is
CarwithCombustionEngine.
-
Snapshot of the current vehicle state.
Declaration
Swift
public var vehicleSnapshot: Vehicle { get } -
Represents current vehicle state.
Setting the new vehicle notifies observers that the vehicle parameters changed. Setting the new vehicle is only expected on the main queue.
Declaration
Swift
public var vehicle: Vehicle { get set } -
Registers vehicle update observer for all vehicle parameter updates. It is expected to be called on the main queue.
Throws
Throws:VehicleError.alreadyRegisteredObserverupon adding the same observer more than once.Declaration
Swift
public func registerVehicleUpdateObserver(_ observer: AnyVehicleUpdateObserver) throwsParameters
observerThe observer to be registered.
-
Registers vehicle update observer for specific vehicle parameter updates. It is expected to be called on the main queue.
Throws
Throws:VehicleError.alreadyRegisteredObserverupon adding the same observer more than once.Declaration
Swift
public func registerVehicleUpdateObserver( _ observer: AnyVehicleUpdateObserver, options: [VehicleUpdateOption] ) throwsParameters
observerThe observer to be registered.
parametersSpecify which parameters should trigger observer notifications.
-
Removes previously registered observer. It is expected to be called on the main queue.
Declaration
Swift
public func unregisterVehicleUpdateObserver(_ observer: AnyVehicleUpdateObserver)Parameters
observerThe registered observer.
-
Updates the vehicle state with specified parameters only.
Throws
VehicleError.invalidVehicleParameterIf vehicleparametersare not valid for the current vehicle type.Updating vehicle state notifies observers of the vehicle parameters changed. It is expected to be called on the main queue.
Declaration
Swift
public func updateVehicleState(with parameters: [VehicleParameter]) throwsParameters
parametersThe vehicle parameters update.
DefaultVehicleProvider Class Reference