Swiftpack.co - what3words/w3w-swift-components-ocr as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by what3words.
what3words/w3w-swift-components-ocr v1.1.3
A UI component for what3words OCR. Uses the camera to scan for three word addresses.
⭐️ 0
🕓 1 week ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/what3words/w3w-swift-components-ocr.git", from: "v1.1.3")


what3words w3w-swift-components-ocr


A Swift component library for what3words OCR. These components can work with either what3words' OCR SDK, or with iOS' Vision Framework.

what3words OCR XCFramework

If you want to use what3words' OCR XCFramework W3WOcrSdk.xcframework, please contact what3words to get it. Otherwise you can use this component as is and rely on iOS's Vision Framework.

Swift Package Manager

Use Swift Package Manager and add the URL below:


Import the libraries wherever you use the components:

import W3WSwiftComponentsOcr
import W3WSwiftApi


You must set the camera permission in your app's Info.plist:

Using The Component

The component constructor needs an OCR object.

Using the API with Vision Framework:

Our W3WOcrNative class that uses iOS' Vision Framework requires our API (or SDK) to be passed into the constructor.

  let api = What3WordsV3(apiKey: "YourApiKey")
  let ocr = W3WOcrNative(api)
  let ocrViewController = W3WOcrViewController(ocr: ocr)

Using the SDK with what3words' OCR SDK:

The what3words OCR SDK requires only a path to the OCR data files, and optionally a language parameter (ISO 2 letter language code).

  let ocr = W3WOcr(dataPath: "/path/to/ocr/datafiles", language: "en")
  let ocrViewController = W3WOcrViewController(ocr: ocr)

Typical Usage

Here's a typical use example set in a UIViewController's IBOutlet function that is connected to a UIButton (presuming the initialisation code above was used somewhere in the class):

@IBAction func scanButtonPressed(_ sender: Any) {

  // show the OCR ViewController
  self.show(ocrViewController, sender: self)
  // start the OCR processing images
  // when it finds an address, show it in the viewfinder
  ocrViewController.onSuggestions = { [weak self] suggestions in
    if let suggestion = suggestions.first {
      self?.ocrViewController.show(suggestion: suggestion)

  // if there is an error show the user
  ocrViewController.onError = { [weak self] error in
    self?.showError(error: error)

Example Code

An example called OcrComponent can be found here in the Examples/OcrComponent directory of this repository.

OCR Reference

Both W3WOcr and W3WOcrNative conform to W3WOcrProtocol. This guarantees the following functions:

set(language: String) - sets a language to use. Langauge codes can be retrieved using the availableLangauges() function.

availableLanguages() -> [String] - returns an array of language codes that the OCR accepts.


Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics