如何找到元组索引?

时间:2017-06-29 13:53:15

标签: ios swift

我有myrecord类..我需要从元组数组中找到对象的索引

var transactionsGroupedByDate = [(String,Array<MyCushyRecords>)]()

我的对象是myrecord对象。

1 个答案:

答案 0 :(得分:0)

var transactionsGroupedByDate = [(String,Array<MyCushyRecords>)]()

我刚刚将MyCushyRecords类的数组更改为[Int]以查找元组的索引,因为我不知道你的模型究竟做了什么,如下所示

var transactionsGroupedByDate = [(String,[Int])]()

现在您可以获得如下所示的索引值

var index:Int? = nil

for i in 0..<transactionsGroupedByDate.count {
    let result = zip(transactionsGroupedByDate[i].1, YOUR_VALUE).enumerated().filter() {
        $1.0 == $1.1
        }.map{$0.0}
  // result gives matches index value from both Int arrays.
    if result.count == YOUR_VALUE.count {
        index = i
        break
    }
}

//here you can check index of specific value in tuples 

if index != nil {
    print(index ?? "failed")
}else {
    print("No matched values")
}