arrays - 在 [[String]] 中查找值的索引

标签 arrays swift

寻找一种方法来检查 [[String]] 数组是否包含一个值,然后找到该值的索引。

[[String]] 数组命名为:“categoriesArray”,包含三个 String 数组

尝试使用 .indexOf 如下:

var location = categoriesArray.indexOf(array1)

但我收到一条错误消息:

无法将“[String]”类型的值转换为预期的参数类型“([String]) throws -> Bool”

谁知道我该如何解决这个问题?

最佳答案

indexOf 或更新版本 index(where:) 将闭包作为参数,而不是您要查找的对象。正确用法:

// index will return optional Int
var location = categoriesArray.index(where:{$0==roundLightArray})

关于arrays - 在 [[String]] 中查找值的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47822706/

相关文章:

ios - 调整图像大小而不损失质量

ios - 如何限制某些不支持 NFC 的设备从应用商店安装 ios 应用程序?

javascript - 具有定义列数的 Reactjs 网格布局

javascript - 重复数组 x 次,然后再次重复删除第一项,直到数组消失

c - 数组是指向第一个元素的指针,如果是……?

swift - 如何使用属性观察者提供的定制?

ios - 5 秒后关闭 UIAlertView Swift

android - 每 5 秒用字符串数组中的每个字符串更新 TextView

c - 为什么我的所有 char 数组都不会被传递(在 C 中)?

iOS swift : How to prepare a cell for reuse