通过recordName查找记录中的索引

时间:2018-11-11 11:36:08

标签: indexing swift4 record id

我有var records = [CKRecord]()

我有record.recordID.recordName

如何查找记录中的record.recordID.recordName在哪个索引上?

我需要它来通过indexPath更新tableView。

1 个答案:

答案 0 :(得分:1)

您可以简单地在数组上使用firstIndex:方法。

let index = arr.firstIndex(where: { r in
  r.recordID.recordName == record.recordID.recordName
})

请注意,索引是可选的,如果在数组中未找到任何元素,则索引将为nil。