I am trying to access the value of "x" in nested loop but each time i try this the value of "x" in inner loop it gets varied.
var downloads_array = [[URL]]()//edited
func downloadImages(){
var count = images.count
let storage = Storage.storage().reference()
for x in 0...count-1{
var anime = [String]()
anime.append(images[x])
anime.append(images[x] + "1")
print("outside the second loop x is : \(x)")
for i in anime{
let storageRef = storage.child("images/\(i).jpg")
storageRef.downloadURL { (url, error) in
if let error = error{
print(error.localizedDescription)
}
else{
print(x)
self.downloads_array[x].append(url!)//edited
}
}
}
}
}
The ouput is:
outside the second loop x is : 0
outside the second loop x is : 1
outside the second loop x is : 2
outside the second loop x is : 3
outside the second loop x is : 4
outside the second loop x is : 5
0
3
0
1
1
4
2
5
3
4
2
5
I am new to swift development please guide me in solving this issue.