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 <a href="https://swiftpackageindex.com/carsxe/carsxe-swift-package" target="\_blank" style={{textDecoration: 'underline'}}>package on Swift Package Index</a>.

## Installation

### Swift Package Manager

Add the CarsXE Swift Package to your project by adding this dependency to your `Package.swift`:

<CodeGroup title="Package.swift">
```swift
// Package.swift (example)
dependencies: [
    .package(url: "https://github.com/carsxe/carsxe-swift-package.git", branch: "main")
]
```
</CodeGroup>

And include it in your target dependencies:

<CodeGroup title="Package.swift">
```swift
// Package.swift (targets example)
targets: [
    .executableTarget(
        name: "YourApp",
        dependencies: [
            .product(name: "carsxe", package: "carsxe-swift-package")
        ]
    )
]
```
</CodeGroup>

### 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:

<CodeGroup title="ContentView.swift">
```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")
    }
}
```
</CodeGroup>

## Basic Usage

### VIN Specifications

<CodeGroup title="VehicleService.swift">
```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)")
        }
    }
}
```
</CodeGroup>

### International VIN Decoder

<CodeGroup title="VehicleService.swift">
```swift
func decodeInternationalVIN() {
    do {
        let intvin = try carsxe.intVinDecoder(["vin": "WF0MXXGBWM8R43240"])
        print(intvin)
    } catch {
        print("Error: \(error)")
    }
}
```
</CodeGroup>

### Market Value

<CodeGroup title="VehicleService.swift">
```swift
func getMarketValue() {
    do {
        let marketvalue = try carsxe.marketValue(["vin": "WBAFR7C57CC811956"])
        print(marketvalue)
    } catch {
        print("Error: \(error)")
    }
}
```
</CodeGroup>

### Vehicle History

<CodeGroup title="VehicleService.swift">
```swift
func getVehicleHistory() {
    do {
        let history = try carsxe.history(["vin": "WBAFR7C57CC811956"])
        print(history)
    } catch {
        print("Error: \(error)")
    }
}
```
</CodeGroup>

### License Plate Decoder

<CodeGroup title="VehicleService.swift">
```swift
func decodePlate() {
    do {
        let decodedPlate = try carsxe.plateDecoder([
            "plate": "7XER187",
            "state": "CA",
            "country": "US"
        ])
        print(decodedPlate)
    } catch {
        print("Error: \(error)")
    }
}
```
</CodeGroup>

### Vehicle Images

<CodeGroup title="VehicleService.swift">
```swift
func getVehicleImages() {
    do {
        let images = try carsxe.images([
            "make": "BMW",
            "model": "X5",
            "year": "2019"
        ])
        print(images)
    } catch {
        print("Error: \(error)")
    }
}
```
</CodeGroup>

### Vehicle Recalls

<CodeGroup title="VehicleService.swift">
```swift
func getRecalls() {
    do {
        let recalls = try carsxe.recalls(["vin": "1C4JJXR64PW696340"])
        print(recalls)
    } catch {
        print("Error: \(error)")
    }
}
```
</CodeGroup>

### Plate Image Recognition

<CodeGroup title="VehicleService.swift">
```swift
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)")
    }
}
```
</CodeGroup>

### VIN OCR from Image

<CodeGroup title="VehicleService.swift">
```swift
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)")
    }
}
```
</CodeGroup>

### Year-Make-Model Search

<CodeGroup title="VehicleService.swift">
```swift
func searchByYearMakeModel() {
    do {
        let yymm = try carsxe.yearMakeModel([
            "year": "2012",
            "make": "BMW",
            "model": "5 Series"
        ])
        print(yymm)
    } catch {
        print("Error: \(error)")
    }
}
```
</CodeGroup>

### OBD Code Decoder

<CodeGroup title="VehicleService.swift">
```swift
func decodeOBDCode() {
    do {
        let obdcode = try carsxe.obdCodesDecoder(["code": "P0115"])
        print(obdcode)
    } catch {
        print("Error: \(error)")
    }
}
```
</CodeGroup>

### Lien and Theft

<CodeGroup title="VehicleService.swift">
```swift
func getLienAndTheft() {
    do {
        let lienTheft = try carsxe.lienAndTheft(["vin": "2C3CDXFG1FH762860"])
        print(lienTheft)
    } catch {
        print("Error: \(error)")
    }
}
```
</CodeGroup>

Start building powerful automotive applications with CarsXE's Swift package!
