Adding vocabularies through a .plist file

We've already covered that Siri understands when a user wants to do something with your application, even if your user uses your app name as a verb. However, your app name might not be the only thing that's specific to your app. Let's look at an example for a workout app.

If a user were to tell Siri, Hey Siri, start an Ultimate Run using RunPotato, Siri would be able to figure out what RunPotato is -- it's the app that is expected to handle the intent. What it won't be able to understand instantly is what it means to start an Ultimate Run. This is where a custom vocabulary entry in a .plist makes a lot of sense.

Custom vocabularies are always provided through the app itself, never through the corresponding extension. To add vocabulary in the form of app-specific words, like the workout name above, an extra .plist file must be added to the app. To add a new .plist file, add a new file to your project and select the Property List file type under the Resource header:

The file you create must be named AppIntentVocabulary. This file contains all of the information about an app's custom vocabulary. The example phrase, Hey Siri, start an Ultimate Run using RunPotato, contains a workout type that Siri can't understand straight away, so we'll need to add this workout to our .plist somehow.

The vocabulary .plist is rather specific and verbose. This is important though, because its purpose is to provide a clear window into the vocabulary our app uses. When we created our AppIntentVocabulary.plist file, Xcode added a dictionary at the top level of our file. This file is a dictionary that will contain all of our custom vocabulary.

For our example phrase, we're going to need a Parameter Vocabularies array. This array will contain Parameter Vocabulary items that specify the vocabulary our app uses for workout names. The first item we should specify is a Parameter Names array. For our app, it contains a single entry: INStartWorkoutIntent.workoutName. We also must add a Parameter Vocabulary dictionary to our entry in the Parameter Vocabularies array.

The Parameter Vocabulary dictionary has keys for the item identifier, synonyms for this identifier, a pronunciation, and even an example phrase. This is all really verbose, but it provides Siri with all of the information it could ever need to resolve user input for your app. The following screenshot shows an example of the entry we'd create for the ultimate run workout: