I have a working function that downloads data from my Firebase Storage, but I don't understand how to actually use the data in my project.
func getImg2() {
let storageRef = storage.reference()
let imageRef = storageRef.child("images/hi2.png")
_ = imageRef.getData(maxSize: 1 * 1024 * 1024) { data, error in
if let error = error {
print(error.localizedDescription)
} else {
let image = UIImage(data: data!)
print("Data: \(data!)")
print("succesfully downloaded \(image!)")
}
}
}
The data gets printed, as well as the image information. I would like to return this data and use it outside the function to load a UIImage. Everything I've tried has given me an error or just returned "0 bytes" for the data. I've been stuck on this for days and would greatly appreciate any help.