Swift Quickstart Guide
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.
Installation
Swift Package Manager
Add the CarsXE Swift Package to your project by adding this dependency to your Package.swift:
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
// Package.swift (targets example)
targets: [
.executableTarget(
name: "YourApp",
dependencies: [
.product(name: "carsxe", package: "carsxe-swift-package")
]
)
]Xcode
In Xcode, go to File → Add Packages... and enter:
https://github.com/carsxe/carsxe-swift-package.git
Setup
First, import the CarsXE package and initialize it with your API key:
ContentView.swift
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")
}
}Basic Usage
VIN Specifications
VehicleService.swift
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)")
}
}
}International VIN Decoder
VehicleService.swift
func decodeInternationalVIN() {
do {
let intvin = try carsxe.intVinDecoder(["vin": "WF0MXXGBWM8R43240"])
print(intvin)
} catch {
print("Error: \(error)")
}
}Market Value
VehicleService.swift
func getMarketValue() {
do {
let marketvalue = try carsxe.marketValue(["vin": "WBAFR7C57CC811956"])
print(marketvalue)
} catch {
print("Error: \(error)")
}
}Vehicle History
VehicleService.swift
func getVehicleHistory() {
do {
let history = try carsxe.history(["vin": "WBAFR7C57CC811956"])
print(history)
} catch {
print("Error: \(error)")
}
}License Plate Decoder
VehicleService.swift
func decodePlate() {
do {
let decodedPlate = try carsxe.plateDecoder([
"plate": "7XER187",
"state": "CA",
"country": "US"
])
print(decodedPlate)
} catch {
print("Error: \(error)")
}
}Vehicle Images
VehicleService.swift
func getVehicleImages() {
do {
let images = try carsxe.images([
"make": "BMW",
"model": "X5",
"year": "2019"
])
print(images)
} catch {
print("Error: \(error)")
}
}Vehicle Recalls
VehicleService.swift
func getRecalls() {
do {
let recalls = try carsxe.recalls(["vin": "1C4JJXR64PW696340"])
print(recalls)
} catch {
print("Error: \(error)")
}
}Plate Image Recognition
VehicleService.swift
func recognizePlateFromImage() {
do {
let plateResult = try carsxe.plateImageRecognition(
imageUrl: "https://api.carsxe.com/img/apis/plate_recognition.JPG"
)
print(plateResult)
} catch {
print("Plate image error: \(error)")
}
}VIN OCR from Image
VehicleService.swift
func extractVINFromImage() {
do {
let vinocr = try carsxe.vinOCR(
imageUrl: "https://api.carsxe.com/img/apis/plate_recognition.JPG"
)
print(vinocr)
} catch {
print("VIN OCR error: \(error)")
}
}Year-Make-Model Search
VehicleService.swift
func searchByYearMakeModel() {
do {
let yymm = try carsxe.yearMakeModel([
"year": "2012",
"make": "BMW",
"model": "5 Series"
])
print(yymm)
} catch {
print("Error: \(error)")
}
}OBD Code Decoder
VehicleService.swift
func decodeOBDCode() {
do {
let obdcode = try carsxe.obdCodesDecoder(["code": "P0115"])
print(obdcode)
} catch {
print("Error: \(error)")
}
}Lien and Theft
VehicleService.swift
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!