arrays - 是否可以找到数组中元组的索引?

标签 arrays swift

Index(of: element)

不适用于元组,有没有办法找到元组的索引?

最佳答案

使用带有 where 子句的索引,这里是具有 2 个成员的元组的示例

let index = array.index {
    $0 == element.0 && $1 == element.1
}

关于arrays - 是否可以找到数组中元组的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45584546/

相关文章:

C - fopen() 的相对路径

java - 在 Java 中存储和访问字符串(通过使用数组)

c - 在c中标记字符串数组

arrays - 计算器程序

iOS - 在 Objective-c 和 Swift 上一起实现 UI

ios - 从 Collection View Controller 调用时, Collection View header 中的 UIButton 不工作,如何解决?

ios - 在带有 Swift View Controller 的 React Native 应用程序中使用 Realm 时出错

php - searchBar.resignFirstResponder() 导致 nil 值

java - 您究竟将数组放在代码中的什么位置?

ios - 无论 IOS 13 中的 View 层次结构如何,都将 ViewController 呈现在所有内容之上