In such a function I get a nil value but I do not understand why. The code in the middle returns an image (and I'm sure about it, I've also checked with some print statements). I do not know how is it possible that it always returns nil. It is like it ignores all the code running in the middle and considers just the first and last statement.
func getImagesDownloaded(reference: StorageReference) -> UIImage {
var imagePassedIn : UIImage?
reference.getData(maxSize: 10*1024*1024) { (data, error) in
guard let imageObject = UIImage(data: data!) else {print("Error has occurred: \(String(describing: error?.localizedDescription))"); return}
imagePassedIn = imageObject
}
if imagePassedIn == nil {
print("Error, getImagesDownloaded is not working")
}
return imagePassedIn!
}