2

No me carga la imagen en el imageview... Este es el código que estoy usando, me ha funcionado en otras ocasiones y ahora no sé porqué arroja ese error.

        let storageRef = self.storage.reference(forURL: self.TLogo1)
        // Download the data, assuming a max size of 1MB (you can change this as necessary)
        storageRef.getData(maxSize: 10 * 1024 * 1024) { (data, error) -> Void in
            // Create a UIImage, add it to the array
            let pic = UIImage(data: data!)
            self.logo1.image = pic
            self.logo1.layer.cornerRadius = 24
            self.logo1.layer.borderWidth = 1.0
            self.logo1.layer.borderColor = UIColor.gray.cgColor
            self.logo1.layer.masksToBounds = true

        }

Este es el error que me arroja:

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
2019-05-15 14:47:56.766952-0400 Tonum[2921:628893] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.

Y de esta manera estoy obteniendo la url desde mi Database

let userID = Auth.auth().currentUser?.uid
        ref.child("A_Usuarios").child(userID!).observe(.value, with: { (snapshot) in
            // Get user value
            let value = snapshot.value as? NSDictionary

                self.TLogo1 = value?["TLogo1"] as? String ?? ""

Cuál será el problema, no me había pasado antes, espero puedan ayudarme...

Muchas gracias!

1 respuesta 1

1

Estas force unwrapping un dato que pudiera ser nulo, por eso te esta tronando, esto esta pasando en tu linea

let pic = UIImage(data:data!)

y lo mas probable es por que en esta linea....

self.TLogo1 = value?["TLogo1"] as? String ?? ""

value["TLogo1"] viene nulo y le estas asignando ""


 let storageRef = self.storage.reference(forURL: self.TLogo1)
        // Download the data, assuming a max size of 1MB (you can change this as necessary)
        storageRef.getData(maxSize: 10 * 1024 * 1024) { (data, error) -> Void in
            // Create a UIImage, add it to the array
            let pic = UIImage(data: data!)
            self.logo1.image = pic
            self.logo1.layer.cornerRadius = 24
            self.logo1.layer.borderWidth = 1.0
            self.logo1.layer.borderColor = UIColor.gray.cgColor
            self.logo1.layer.masksToBounds = true

        }

entonces lo que debes de hacer es...

let storageRef = self.storage.reference(forURL: self.TLogo1)
        // Download the data, assuming a max size of 1MB (you can change this as necessary)
        storageRef.getData(maxSize: 10 * 1024 * 1024) { (data, error) -> Void in
            // Create a UIImage, add it to the array
            guard let pic = UIImage(data: data?) else { return }
            self.logo1.image = pic
            self.logo1.layer.cornerRadius = 24
            self.logo1.layer.borderWidth = 1.0
            self.logo1.layer.borderColor = UIColor.gray.cgColor
            self.logo1.layer.masksToBounds = true

        }

O buscar alguna otra manera de no hacer force unwrapping al data del closure

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.