Through Firebase I'm calling many url to convert it to UIImage but aren't displayed in a corrected order. The print func stamp to the consolle the current index:
0 2 1 3 4
The JSON is like:
{
"evento_1" = "http://.altervista.org/evento1.jpeg";
"evento_2" = "http://.altervista.org/evento2.jpeg";
"evento_3" = "http://.altervista.org/evento3.jpeg";
"evento_4" = "http://.altervista.org/evento4.jpeg";
"evento_5" = "http://.altervista.org/evento5.jpeg";
}
Function to get the data:
ref.observeEventType(.Value, withBlock: { snapshot in
let nsDictionary = snapshot.value as? NSDictionary
for (key, value) in nsDictionary! {
dict[key as! String] = value
}
var index = 0
for (_, url ) in dict {
self.loadImage(url as! String, i: index)
index++
}
}, withCancelBlock: { error in
print(error.description)
})
Image Loader func:
func loadImage(urlString:String,i:Int)
{
let url = NSURL(string: urlString)
let data = NSData(contentsOfURL: url!)
self.eventi[i].image = UIImage(data: data!)
}