func cellConfiguration(cell: UserListCell, for indexPath: IndexPath) {
let profile = profiles[indexPath.row]
if let name = profile.login {
cell.nameLabel.text = "Name: \(name.capitalized)"
}
if let id =
profile.id {
cell.idLabel.text = "ID: \(id)"
}
cell.userImage.layer.cornerRadius = 8
cell.userImage.clipsToBounds = true
cell.activityIndicator.startAnimating()
cell.activityIndicator.hidesWhenStopped = true
guard let imageUrl = profile.avatarUrl else {return}
guard let url = URL(string: imageUrl) else {return}
if let imageUrlCache = imageCach.object(forKey: imageUrl as NSString) as? URL {
if let data = try? Data(contentsOf: imageUrlCache) {
cell.userImage.image = UIImage(data: data)
}
} else {
let session = URLSession.shared
session.dataTask(with: url) { (data, _, error) in
if let error = error {
print(error.localizedDescription)
return
}
if let data = data, let image = UIImage(data: data) {
DispatchQueue.main.async {
cell.userImage.image = image
cell.activityIndicator.stopAnimating()
}
}
}.resume()
}
}