Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
¿Cómo compartir imágenes descargadas del almacenamiento de Firebase entre diferentes vistas?

Este es el código que uso para obtener la imagen del almacenamiento. Funciona a las mil maravillas, pero no quiero volver a descargarlo en diferentes vistas de nuevo.

 func retreiveImagesFromFireBase(downloadUrl:String,imageHolder:UIImageView){ if downloadUrl != "" { let storageRef = Storage.storage().reference(forURL: downloadUrl) // Download the data, assuming a max size of 1MB (you can change this as necessary) storageRef.getData(maxSize: 5*1024*1024) { (data, error) in if error == nil { if let pic = UIImage(data: data!) { imageHolder.image = pic } } else { print(error) } } } }

¿Cómo debería manejar esto?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Simplemente declare UIImage globalmente en su clase, y dentro de su función, donde está configurando imageHolder, asigne esa imagen descargada a la imagen global y utilícela donde quiera.

 UIImage image; func retreiveImagesFromFireBase(downloadUrl:String,imageHolder:UIImageView){ if downloadUrl != ""{ let storageRef = Storage.storage().reference(forURL: downloadUrl) // Download the data, assuming a max size of 1MB (you can change this as necessary) storageRef.getData(maxSize: 5*1024*1024) { (data, error) in if error == nil{ if let pic = UIImage(data: data!){ imageHolder.image = pic image = pic // use it on other views } }else{ print(error) } } } }
over 4 years ago · Santiago Trujillo Report

0

Si solo tiene una o dos image , userdefault almacene en userdefault del usuario y luego puede acceder a cualquier controlador data vista. imagen

 let image = UIImage(data: imageData)
over 4 years ago · Santiago Trujillo Report

0

Tu puedes hacer

 class Service { static let shared = Service() var image1:UIImage? var image2:UIImage? let imageLink = "//////" // or with SDWebImage } if let pic = UIImage(data: data!){ Service.shared.image = pic }

O use SDWebImage y comparta el enlace, también puede hacer una var global como

 var image:UIImage?

pero no se recomienda ya que no tiene agrupación para que el desarrollador sepa que es fuente local/instancia/global, por lo que es confuso a diferencia de singleton

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!