I hope you can help me with this one.
I am trying to download an image from a url and the set it to a label. I am able to show it in a imageView but not a label.
This is my code.
func updateImage() {
let ref = Database.database().reference()
let uid = Auth.auth().currentUser?.uid
let usersRef = ref.child("users").child(uid!)
// only need to fetch once so use single event
Database.database().reference().child("Products").queryOrderedByKey().observe(.childAdded, with: { snapshot in
if !snapshot.exists() { return }
//print(snapshot)
let userInfo = snapshot.value as! NSDictionary
print(userInfo)
print(userInfo["name"]!)
let profileUrl = userInfo["photoURL"] as! String
print(profileUrl)
let storageRef = Storage.storage().reference(forURL: profileUrl)
storageRef.downloadURL(completion: { (url, error) in
do {
let data = try Data(contentsOf: url!)
let image = UIImage(data: data as Data)
self.productPhoto.image = image
}
catch _ {
// Error handling
}
})
})
}
I have tried many things like this
self.swipeLabel.backgroundColor = UIColor(patternImage: UIImage(named: image))
Thank you in advance