# Creating an AutoSuggest text field with Objective-C

Adding a 3 word address textfield with an AutoSuggest tableview dropdown

Topics: Objective-C, Mobile App

Source: https://developer.what3words.com/tutorial/creating-an-autosuggest-text-field-with-objective-c

Updated: 2026-11-27

### Step by step

The Objective-C library provides UITexfield component to make using the what3words API even easier. In this tutorial we will go through using a component from the wrapper which allows the developer to add a search input to their app, powered by the what3words API AutoSuggest function. As you will see it is straightforward to use and allows you to configure it for your needs using a range of properties.

Full sample apps for the component can be found in our Github repo

[iOS Sample Apps](https://github.com/what3words/w3w-swift-samples)

## 1. Get API key

You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/).

## 2. Installation

You can use [CocoaPods](http://cocoapods.org/) to install `w3w-objectivec-wrapper`by adding it to your `Podfile`:

### CocoaPods (iOS 8+, OS X 10.10+)

**Objective-C**

```objective-c
platform :ios, '10.0'
use_frameworks!

target 'MyApp' do
    pod 'W3wSuggestionField', :git => 'https://github.com/what3words/w3w-autosuggest-textfield-objectivec.git'
end
```

## 3. Usage

Add the following import statement to the class

**Objective-C**

```objective-c
#import <W3wTextField.h>
```

Select `ViewController.m` and add the following code to the class

**Objective-C**

```objective-c
@property (weak, nonatomic) IBOutlet W3wTextField *suggestionField;
```

Now, open Main.storyboard and drag a `UITextfield` to the screen from the Object library. In the Identity Inspector change the custom class to `W3wTextField`. The last thing to do is to connect the action to the button. Click the yellow View Controller icon in the View Controller scene.

From the Connections Inspector (last tab on the right sidebar), click and drag the open circle next to `suggestionField` to newly created `UITextfield` in the storyboard.

Initialize the API by placing the following code into the `-viewDidLoad` method

**Objective-C**

```objective-c
[self.suggestionField setAPIKey:@"<Secret API Key>"];
```

To get selected 3 word address from dropdown menu, add the following code to the `ViewController.m` class

**Objective-C**

```objective-c
[self.suggestionField didSelect:^(NSString *selectedText) {
    NSLog(@"Three word address: %@", selectedText);
  }];
```

### Available properties

There are a range of customisation properties you can use to configure the AutoSuggest component.

| Parameter | Type | Description |
| --- | --- | --- |
| autoFocus | string | comma separated lat/lng of point to focus on. Example value:"51.521251,-0.203586" |
| clipToCountry | string | confine results to a given country or comma separated list of countries. Example value:"GB,US" |
| clipToBoundingBox | string | Confine results to a bounding box specified using co-ordinates. Example value:"51.521,-0.343,52.6,2.3324" |
| clipToCircle | string | Restrict AutoSuggest results to a circle, specified by lat,lng,kilometres, where kilometres in the radius of the circle. For convenience, longitude is allowed to wrap around 180 degrees. For example 181 is equivalent to -179. |
| clipToPolygon | string | Restrict AutoSuggest results to a polygon, specified by a comma-separated list of lat,lng pairs. The polygon should be closed, i.e. the first element should be repeated as the last element; also the list should contain at least 4 entries. The API is currently limited to accepting up to 25 pairs. Example value:"51.521,-0.343,52.6,2.3324,54.234,8.343,51.521,-0.343" |

## 4. Troubleshooting

If you encounter errors or issues related to convert-to-coordinate, convert-to-3wa and grid-section requests while using the Free plan, please check the network panel for the following error message `Error 402 payment required` and its response, indicating the need to upgrade to a higher plan:

**JSON**

```json
{
    "error": {
        "code": "QuotaExceeded",
        "message": "Quota exceeded or API plan does not have access to this feature. Please change your plan at https://accounts.what3words.com/select-plan, or contact support@what3words.com"
    }
}
```

For more information, visit our [API plans page](https://accounts.what3words.com/select-plan). If you need further assistance, contact [support@what3words.com](mailto:support@what3words.com).
