所以我的代码一直有问题,特别是在我有这些数组的地方:
var messageIntents = ["Send a message", "Send message", "Text", "Send text", "Send a text"]
var weatherIntents = ["weather", "what's the weather", "how's the weather", "the weather"]
var musicIntents = ["play", "i want to hear", "shuffle"]
目标是检查字符串是否等于数组中的值之一。我不想一个一个地检查这些数组,而是想制作一个数组来检查它们。那可能吗?我将如何检查它?
最佳答案
您可以像这样 [[Any]] 简单地将数组添加到数组内部。
var messageIntents = ["Send a message", "Send message", "Text", "Send text", "Send a text"]
var weatherIntents = ["weather", "what's the weather", "how's the weather", "the weather"]
var musicIntents = ["play", "i want to hear", "shuffle"]
下面是数组占位符内的数组示例。
var arraysOfArray = [messageIntents, weatherIntents,musicIntents]
您可以通过每次循环数组的索引来访问对象
arraysOfArray[index]
arraysOnArray[0] //prints ["Send a message", "Send message", "Text", "Send text", "Send a text"]
或者像这样使用'for each'语句
for array in arraysOfArray{
print(array)
for dataObject in array{
print(dataObject)
}
}
关于arrays - 快速制作一个数组数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51296328/