# \[VNClassificationObservation\] enumerated()

**URL:** <https://forums.kodeco.com/t/vnclassificationobservation-enumerated/38083>\
**Category:** Swift\
**Created:** [December 29, 2017, 10:13pm UTC](https://forums.kodeco.com/t/vnclassificationobservation-enumerated/38083 "2017-12-29T22:13:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jingo\_man](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jingo_man/32/81494_2.png) [@jingo\_man](https://forums.kodeco.com/u/jingo_man)\
**Post date:** [December 29, 2017, 10:13pm UTC](https://forums.kodeco.com/t/vnclassificationobservation-enumerated/38083/1 "2017-12-29T22:13:22Z")

</div>

Trying some CoreML stuff, with an image classification. I am inside the loop of the results taken from the video feed, which is updating for every frame taken and doesn’t occur on the main thread.

For debugging, I need to see the array’s index number that the returned results are in. I have put a loop counter (type Int) but think the background threading is messing this up (viewing the SQLite DB afterwards anyway!).

I have now tried to use the array.enumerated() approach, so I am directly able to print the index value, but cannot get any working syntax.

Current code is:

```
if let results = request.results as? [VNClassificationObservation] {
   var counter = 0

   for item in results[0...9] {
      print("\(counter): \(item.identifier) | \(item.confidence)")

      DispatchQueue.main.async {
           // Update the UI, but in debugging, printing the current counter var
           print("\(counter): \(item.identifier) | \(item.confidence)")
      }
   counter += 1
}

```

On the “for loop” line, I have tried a few variations, such as:

```
for (index, element) in results[0...9] {
for (index, element) in results.enumerated()[0...9] {

```

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [June 14, 2018, 2:13pm UTC](https://forums.kodeco.com/t/vnclassificationobservation-enumerated/38083/2 "2018-06-14T14:13:26Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
