Get started with CarsXE's Swift package to integrate comprehensive vehicle data into your iOS, macOS, and other Swift applications.
The CarsXE Swift package provides a simple and powerful way to integrate vehicle data into your Swift applications across iOS, macOS, tvOS, and watchOS. This guide will help you get started quickly.
For more information, see the package on Swift Package Index.
Add the CarsXE Swift Package to your project by adding this dependency to your Package.swift:
// Package.swift (example)
dependencies: [
.package(url: "https://github.com/carsxe/carsxe-swift-package.git", branch: "main")
]And include it in your target dependencies:
// Package.swift (targets example)
targets: [
.executableTarget(
name: "YourApp",
dependencies: [
.product(name: "carsxe", package: "carsxe-swift-package")
]
)
]In Xcode, go to File → Add Packages... and enter:
https://github.com/carsxe/carsxe-swift-package.git
First, import the CarsXE package and initialize it with your API key:
import SwiftUI
import carsxe
struct ContentView: View {
// Initialize the client
let carsxe = CarsXE(apiKey: "YOUR_API_KEY_HERE")
var body: some View {
// Your UI code here
Text("CarsXE Example")
}
}import carsxe
class VehicleService {
private let carsxe = CarsXE(apiKey: "YOUR_API_KEY_HERE")
func decodeVIN() {
let vin = "WBAFR7C57CC811956"
do {
let vehicle = try carsxe.specs(["vin": vin])
if let input = vehicle["input"] as? [String: Any],
let vinValue = input["vin"] as? String {
print("VIN: \(vinValue)")
}
} catch {
print("Error: \(error)")
}
}
}func decodeInternationalVIN() {
do {
let intvin = try carsxe.intVinDecoder(["vin": "WF0MXXGBWM8R43240"])
print(intvin)
} catch {
print("Error: \(error)")
}
}func getMarketValue() {
do {
let marketvalue = try carsxe.marketValue(["vin": "WBAFR7C57CC811956"])
print(marketvalue)
} catch {
print("Error: \(error)")
}
}func getVehicleHistory() {
do {
let history = try carsxe.history(["vin": "WBAFR7C57CC811956"])
print(history)
} catch {
print("Error: \(error)")
}
}func decodePlate() {
do {
let decodedPlate = try carsxe.plateDecoder([
"plate": "7XER187",
"state": "CA",
"country": "US"
])
print(decodedPlate)
} catch {
print("Error: \(error)")
}
}func getVehicleImages() {
do {
let images = try carsxe.images([
"make": "BMW",
"model": "X5",
"year": "2019"
])
print(images)
} catch {
print("Error: \(error)")
}
}func getRecalls() {
do {
let recalls = try carsxe.recalls(["vin": "1C4JJXR64PW696340"])
print(recalls)
} catch {
print("Error: \(error)")
}
}func recognizePlateFromImage() {
do {
let plateResult = try carsxe.plateImageRecognition(
imageUrl: "https://imagedelivery.net/moyiiSImjJPI_EZVxNMBBw/f49aed53-d736-4370-f3f4-97418841c800/public"
)
print(plateResult)
} catch {
print("Plate image error: \(error)")
}
}func extractVINFromImage() {
do {
let vinocr = try carsxe.vinOCR(
imageUrl: "https://imagedelivery.net/moyiiSImjJPI_EZVxNMBBw/f49aed53-d736-4370-f3f4-97418841c800/public"
)
print(vinocr)
} catch {
print("VIN OCR error: \(error)")
}
}func searchByYearMakeModel() {
do {
let yymm = try carsxe.yearMakeModel([
"year": "2012",
"make": "BMW",
"model": "5 Series"
])
print(yymm)
} catch {
print("Error: \(error)")
}
}func decodeOBDCode() {
do {
let obdcode = try carsxe.obdCodesDecoder(["code": "P0115"])
print(obdcode)
} catch {
print("Error: \(error)")
}
}func getLienAndTheft() {
do {
let lienTheft = try carsxe.lienAndTheft(["vin": "2C3CDXFG1FH762860"])
print(lienTheft)
} catch {
print("Error: \(error)")
}
}Start building powerful automotive applications with CarsXE's Swift package!