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] {