How to Create a UPC-E Barcode in Swift
In this quick tutorial, we will demonstrate a simple solution for validating and creating a UPC-E barcode image in Swift. Utilizing the following API, instead of attempting to manually build the code, will enable you to save time and increase productivity across the board. So without any further ado, we’ll dive right in.
All you will need for this process is to input the UPC-E barcode value and your API key into the below code:
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endifvar semaphore = DispatchSemaphore (value: 0)let parameters = "0=%3C&1=s&2=t&3=r&4=i&5=n&6=g&7=%3E"
let postData = parameters.data(using: .utf8)var request = URLRequest(url: URL(string: "https://api.cloudmersive.com/barcode/generate/upc-e")!,timeoutInterval: Double.infinity)
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.addValue("YOUR-API-KEY-HERE", forHTTPHeaderField: "Apikey")request.httpMethod = "POST"
request.httpBody = postDatalet task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}task.resume()
semaphore.wait()
Your downloadable PNG barcode file will be waiting for you at the end of the operation! If you need to obtain an API key, you can do so by register for a free account on the Cloudmersive website; this provides 800 calls/month across any of our APIs.