Irrd Irrd - 1 year ago 86
Swift Question

How to get the index of a specific object in Dictionary in swift

I am searching a value of a key in

Dictionary Array
in this way.

if let result = self.lasrIDArray.flatMap({$0["\(self.selectedTitle)"]}).first {
print("-------RESULT------\(result)") //->title of the other

But wat I want to do is take the index of this
contains object.

How can I do that?

Answer Source

You can enumerate array:

if let indexAndResultTuple = (self.lasrIDArray.enumerate().flatMap{($0.index, $0.element["\(self.selectedTitle)"])}).first {
    let index = indexAndResultTuple.0
    let result = indexAndResultTuple.1

    print("-------RESULT------\(result) --atIndex--\(index)") //->title of the other
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download