Я пытаюсь отобразить мой JSON в моем UIImageView и UILabel. У меня есть JSON в моей консоли, но он не представлен на ярлыке или в ImageView. Я не получаю ошибок, но ничего не отображается с использованием следующего JSON.
override func viewDidLoad()
{
print(currentUser!)
super.viewDidLoad()
loadUser()
refreshControl?.tintColor = .black
self.tableView.addSubview(refreshControl!)
}
func loadUser()
{
// save method of accessing user related info in global var
guard let firstName = currentUser?["firstName"], let lastName = currentUser?["lastName"], let username = currentUser?["username"], let profileImage = currentUser?["profileImage"] else
//guard let firstName = currentUser?["firstName"], let lastName = currentUser?["lastName"], let username = currentUser?["username"], let profileImagePath = currentUser?["profileImage"] else
{
return
}
fullNameLabel.text = "\((firstName as! String).capitalized) \((lastName as! String).capitalized)" // "Bob Michael"
usernameLabel.text = "@\(username as! String)"
Helper().downloadImage(from: profileImage as! String, showIn: self.ProfileImageView, orShow: "")
}
// allows us to download the image from certain url string
func downloadImage(from path: String, showIn imageView: UIImageView, orShow placeholder: String) {
// if avaPath string is having a valid url, IT'S NOT EMPTY (e.g. if ava isn't assigned, than in DB the link is stored as blank string)
if String(describing: path).isEmpty == false {
DispatchQueue.main.async {
// converting url string to the valid URL
if let url = URL(string: path) {
// downloading all data from the URL
guard let data = try? Data(contentsOf: url) else {
imageView.image = UIImage(named: placeholder)
return
}
// converting donwloaded data to the image
guard let image = UIImage(data: data) else {
imageView.image = UIImage(named: placeholder)
return
}
// assigning image to the imageView
imageView.image = image
}
}
}
}