Swiftpack.co - Package - colbylwilliams/CustomVision


Swift SDK for Microsoft's Custom Vision Service



  • iOS 11.0+ / Mac OS X 10.11+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 9.3+
  • Swift 4.1+
  • Custom Vision Account



Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate CustomVision into your Xcode project using Carthage, specify it in your Cartfile:

github "colbylwilliams/CustomVision"

Run carthage update to build the framework and drag the built CustomVision.framework into your Xcode project.


Coming soon

Swift Package Manager

Coming soon


To get started using CustomVision, you need to provide the SDK with your Training Key and Prediction Key.

If you're working with a single project, you can also provide a default Project ID that will be used for every project operation (instead of passing it in as a parameter every time).

There are two ways to provide the Training Key, Prediction Key, and Project ID; programmatically, or by adding them to a plist file:


The simplest way to provide these values and start using the SDK is to set the values programmatically:

CustomVisionClient.defaultProjectId     = "CUSTOM_VISION_PROJECT_ID"
CustomVisionClient.shared.trainingKey   = "CUSTOM_VISION_TRAINING_KEY"
CustomVisionClient.shared.predictionKey = "CUSTOM_VISION_PREDICTION_KEY"

CustomVisionClient.shared.getIterations { r in
    // r.resource is [Iteration]

Plist File

Alternatively, you can provide these values in your project's info.plist, a separate CustomVision.plist, or provide the name of your own plist file to use.

Simply add the CustomVisionTrainingKey, CustomVisionPredictionKey, and CustomVisionProjectId keys and provide your Training Key, Prediction Key, and default Project ID respectively.

Note: This method is provided for convenience when quickly developing samples and is not recommended to ship these values in a plist in production apps.




Or add a CustomVision.plist file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

Named plist

Finally, you can CustomVisionTrainingKey, CustomVisionPredictionKey, and CustomVisionProjectId key/values to any plist in your project's main bundle and provide the name of the plist:

CustomVisionClient.shared.getKeysFrom(plistNamed: "SuperDuperDope")

Training Images

The CustomVision SDK adds several convenience functions to make uploading new training images to your project as easy as possible.

This example demonstrates creating a new Tag in the Custom Vision project, then uploading several new training images to the project, tagging each with the newly created tag:

let client = CustomVisionClient.shared

let tag = "New Tag"     // doesn't exist in project yet
let images: [UIImage] = // several UIImages

client.createImages(from: images, withNewTagNamed: name) { r in
    // r.resource is ImageCreateSummary

Export & Download CoreML models

One of the most useful features of this SDK is the ability to re-train your Project, export the newly trained model (Iteration), download to the phone's file system, and compile the model on-device for use with CoreML.

func updateUser(message: String) {
    // update user

let client = CustomVisionClient.shared 

client.trainAndDownloadCoreMLModel(withName: "myModel", progressUpdate: updateUser) { (success, message) in


Once the compiled model is persisted to the devices filesystem (above) you get the url of the model using the client's getModelUrl() func:

if let url = client.getModelUrl() {
    let myModel = try MLModel(contentsOf: url)


Licensed under the MIT License. See LICENSE for details.


Stars: 1
Help us keep the lights on


Used By

Total: 0


v0.3.4 - Jul 30, 2018

update swift version

v0.3.3 - Apr 29, 2018

  • Fix url encoding tags

v0.3.2 - Apr 29, 2018

  • Fix incorrect URL

v0.3.1 - Apr 29, 2018

v0.2.3 - Apr 28, 2018

  • Equatable