Swift wrapper for the what3words API
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Apple's Swift wrapper for the what3words API (see http://developer.what3words.com/api)

Getting started

Open up the AppDelegate file and edit the first line in application:didFinishLaunchingWithOptions: to be like so:

static let apiKey = "" // Your W3W API Key

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    W3W.configuration = W3W.Configuration(apiKey: apiKey)
    return true

This line configures all the API request performed during the lifetime of your application.

Default language (en)

It can also receive a language abbreviation from what3words's provided list (see http://developer.what3words.com/additional-reference-docs/#apilanguages)

W3W.configuration = W3W.Configuration(apiKey: apiKey, language: "it")

API Methods

Convert 3 words to position

This is the core method for taking a 3 word address and turning it into a pair of latitude,longitude coordinates. (see: http://developer.what3words.com/api/#3toposition)

W3W.toPosition(["jaunts", "jokers", "darling"], handler: { result, error in }) // -2.142208,-79.857958

Convert position to 3 words

This is the core method for taking latitude,longitude coordinates and turning them into a 3 word address. (see: http://developer.what3words.com/api/#positionto3)

W3W.toWords([40.712794, -74.005924], handler: { result, error in }) // bets.update.those


Both methods' first parameter can be a single string joined by a '.' and ',' respectively. Both methods above can also receive a 'language' and 'corners' parameter to override the defaults.

Get list of available 3 word languages

Retrieve a list of available 3 word languages (see: http://developer.what3words.com/api/#getlanguages)

W3W.availableLanguages({ result, error in })

Error Handling

W3W's Error contains information of possible errors that come back from the API. (see: http://developer.what3words.com/additional-reference-docs/#apierrorcodes)

switch error! {
  case let error as W3WError: break
  case let error as NSError: break
  default: break