Build Violet into your iOS Mobile App

The Violet iOS SDK helps you build integrations into the Violet API from your iOS applications. We provide you with out-of-the-box API connections and Object models so that you can power full e-commerce flows without any extra effort.

Before you Begin

Ensure you have the following installed on your local environment before running our sample applications.

Getting Started

Running the Proxy Server

Run the Express Proxy Server in your local environment by following the guide. This will serve as an authentication layer for your client-side application. The iOS SDK by default routes all API calls through this proxy server.

Adding Violet iOS SDK to XCode

  1. In XCode, select File > Add Packages… and enter https://github.com/violetio/violet-swift.git as the repository URL.
  2. Select the latest version from our releases page.

For details on the latest SDK release and past versions, see the  page on GitHub. To receive notifications when a new release is published, .

Interacting with the SDK

This SDK provides the models and API Client for calls to Violet. You can import the SDK into your .swift file and make calls as follows:

Search Offers

Swift
class CatalogSearchOffersRequest {
    let page: Int
    let size: Int
    var pageOfferResponse: PageOffer? = nil

    init(page: Int = 1, size: Int = 20) {
        self.page = page
        self.size = size
    }

    func send() {
        CatalogOffersAPI.searchOffers(body: OfferSearchRequest(merchantId: 10000))
        { [weak self] data, error in
            guard let self = self else { return }

            if let anError = error {
                print("\(anError.localizedDescription)")
            } else if let aPageOffer = data {
                self.pageOfferResponse = aPageOffer
            }
        }
    }
}

Add SKU to Cart

Swift
import Violetlet cartId = 987 // Int64 |
let priceCart = true // Bool |  (optional) (default to false)
let async = true // Bool |  (optional) (default to true)
let body = OrderSku(appId: 123, available: false, brand: "brand_example", externalId: "externalId_example", height: 123, id: 123, length: 123, linePrice: 123, merchantId: 123, name: "name_example", orderSkuRates: [OrderSkuRate(amount: 123, decimalRate: 123, dollarAmount: 123, name: "name_example", orderSkuId: 123, rate: 123, type: "type_example")], price: 123, productId: "productId_example", productType: "productType_example", quantity: 123, quantityFulfilled: 123, skuId: 123, status: "status_example", thumbnail: "thumbnail_example", transientExternalProductId: "transientExternalProductId_example", weight: 123, width: 123) // OrderSku |  (optional)// Add SKU to Cart
CheckoutItemsAPI.addSkuToCart(cartId: cartId, priceCart: priceCart, async: async, body: body) { (response, error) in
    guard error == nil else {
        print(error)
        return
    }if (response) {
        dump(response)
    }
}

For a full list of APIs available, please refer to the README for the latest release.