[ad_1]
I’m making an attempt to retrieve knowledge from firebase and show them in a tableview however my code for some motive just isn’t working. I get the pictures and appending them into an inventory however that checklist just isn’t having any knowledge outdoors the else block.
With my implementation, I get a clean tableview. May somebody assist with me this please?
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var tableView: UITableView!
let db = Firestore.firestore()
var usersReference = Firestore.firestore().assortment("customers")
var storageReference = Storage.storage().reference()
var imagesList = [UIImage]()
override func viewDidLoad() {
tremendous.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
usersReference.addSnapshotListener { [self] (querySnapshot, error) in
querySnapshot?.paperwork.forEach() {
(doc) in
let uid = doc.knowledge()["uid"] as! String
let imagePath = "profilePictures/(uid).jpg"
let imgRef = storageReference.youngster(imagePath)
imgRef.getData(maxSize: 1 * 2048 * 2048) { knowledge, error in
if let error = error {
print(String(describing: error))
}
else {
DispatchQueue.essential.async {
let picture = UIImage(knowledge: knowledge!)
imagesList.append(picture!)
print("inside viewDidLoad: ", imagesList.depend)
}
}
}
}
}
print(imagesList.depend)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
return imagesList.depend
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "imageCell", for: indexPath)
print("cellForRowAt: ",imagesList.depend)
cell.textLabel?.textual content = "(indexPath.row)"
cell.imageView?.picture = imagesList[indexPath.row]
return cell
}
That is how my simulator seems like after I run the code: compiled code .
[ad_2]
