Я хочу загрузить сообщения моего текущего пользователя из моей базы данных Firebase.
Это архитектура моей базы данных:
Я уже успешно загрузил все сообщения в домашний вид, нокогда я попытался продублировать и использовать тот же метод здесь с необходимыми изменениями и использованием uid для сообщений текущего пользователя, он ничего не показывает ... У меня закончились идеи о том, в чем может быть проблема, мог бы использовать некоторую помощь.
Вот снимок экрана из swift-файла ProfileUserPosts: ![enter image description here](https://i.stack.imgur.com/jxMJo.png)
//VARS
var postsuser = [ProfileUserPosts]()
@objc func observeUserPosts() {
let uid = Auth.auth().currentUser?.uid
let postsRef = Database.database().reference().child("posts").child("author")
postsRef.queryOrdered(byChild: "userid").queryEqual(toValue: uid!).observe(.value) { (snapshot) in
var tempPost = [ProfileUserPosts]()
for child in snapshot.children {
if let childSnapshot = child as? DataSnapshot {
let dict = childSnapshot.value as? [String: Any]
//Post Picture
let photoUrl = dict!["photoUrl"] as? String
let url = URL(string: photoUrl!)
//Info Post
let comments = dict!["comments"] as? String
let city = dict!["city"] as? String
let municipality = dict!["municipality"] as? String
let breed = dict!["breed"] as? String
let phoneuser = dict!["phone"] as? String
let postType = dict!["postType"] as? String
let petType = dict!["petType"] as? String
let gender = dict!["gender"] as? String
let timestampadoption = dict!["timestamp"] as? Double
let date = Date(timeIntervalSince1970: timestampadoption!/1000)
let post = ProfileUserPosts(breed: breed!, phone: phoneuser!, photoUrl: url!, city: city!, municipality: municipality!, petType: petType!, gender: gender!, timestamp: date, postType: postType!, comments: comments!)
tempPost.insert(post, at: 0)
}
DispatchQueue.main.async {
self.postsuser = tempPost
self.postsCollectionView.reloadData()
self.refresher.endRefreshing()
}
}
}
}
Здесь я загружаю CollectionView с помощью numberOfItemsInSection и cellForItem
extension ProfileViewController: UICollectionViewDataSource,UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return postsuser.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: PostsCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "postsCell", for: indexPath) as! PostsCollectionViewCell
cell.set(post: postsuser[indexPath.row])
return cell
}
}