This may not be the best approach, but I think it might work, considering the code provided:
var jpgCount = 0
while let file = files?.nextObject() as? String {
if file.hasSuffix(".jpg") || file.hasSuffix(".jpeg") {
jpgCount += 1
print(file)
}
}