My understanding is that, you intend to categorize a string. If you intend to directly compare them ( by direct compare i mean no transformation during checking like hasPrefix, hasSuffix, contains, toLowerCase, toUpperCase ), then using a dictionary is the fastest way.
To do it in a cleaner way first of all declare an enum for categories
enum IntentCategories {
case message
case weather
case music
case none
}
Then storing the string keys in dictionary like following
var intents [String: IntentCategories] = [
"Send a message" : IntentCategories.message,
"Send message" : IntentCategories.message,
"Text" : IntentCategories.message,
"weather" : IntentCategories.weather
//... insert all the intents for message, hope you get my point
]
Then finding the string checking for particular intent category
switch intents[INPUT_STRING] {
case message:
print("Message type intent detected")
case weather:
print("weather type intent detected")
case music:
print("music type intent detected")
case none:
print("undefined intent detected")
}
This implementation will give you the fastest possible way to categorize your intent strings.
If you need transformation of existing intent before comparing, there is no quick way except linearly searching each intent strings.
Hope it helps.
let intents = [messageIntents, weatherIntents, musicIntents]for an array of arrayslet intents = messageIntents + weatherIntents + musicIntentsfor a single array with all elements, thenif intents.contains("Send message") { print("found it!") }