I am new to swift and currently working on an application where I need to download an image that I stored on firebase cloud storage. One issue I am having is that I try to download it using the code directly from the firebase documentation which you can see below.
// Create a reference to the file you want to download
let islandRef = storageRef.child("images/island.jpg")
// Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes)
islandRef.getData(maxSize: 1 * 1024 * 1024) { data, error in
if let error = error {
// Uh-oh, an error occurred!
} else {
// Data for "images/island.jpg" is returned
let image = UIImage(data: data!)
}
}
But as you can see that image property seems to get lost in that closure, but obviously I want to be able to use that image and set it to be the image property of an imageview in my app. I wanted to know what I could do to allow that image to persist outside of that call back function for .getData