У меня есть структура в базе данных firestore, такая как форма объекта.Мне нужно получить данные из пожарного магазина и отобразить их в виде таблицы в формате swift
-
collection//users
-authid
- collection//Split
- auth id
- collection//SentInvitations
-automatic id
-Invitee(i)(object)
.name:bnnn
.phonenumber:567788
.amount:123
- Invitee(2)
.name:aaaa
.phonenumber:987654321
.amount:198
, где i = no.of приглашенных. Теперь мне нужно извлечь всех этих приглашенных и отобразить в виде таблицы
Код Я пытался получить данные из пожарного магазина
func loadData(){
let authid = Auth.auth().currentUser?.uid
let docRef = db.collection("deyaPayUsers").document(authid!).collection("Split").document(authid!).collection("SentInvitations").document(senderautoid!)
docRef.getDocument { (document, error) in
if let city = document.flatMap({
$0.data().flatMap({ (data) in
return Invite(dictionary: data)
})
}) {
print("City: \(city)")
} else {
print("Document does not exist")
}
}
}
и мой класс модели Пригласить
import Foundation
import FirebaseFirestore
protocol DocumentSerializable2
{
init?(dictionary:[String:Any])
}
struct Invite {
var PhoneNumber:Int
var Amount:Int
//var Status:String
var dictionary:[String:Any]{
return [
"PhoneNumber":PhoneNumber,
"Amount":Amount,
]
}
}
extension Invite : DocumentSerializable2{
init?(dictionary: [String:Any]){
guard let amount = dictionary["Amount"] as? Int,
let phonenumber = dictionary["PhoneNumber"] as? Int else { return nil}
self.init(PhoneNumber:phonenumber, Amount:amount)
}
}
когда я выполняю этот код, он выполняется, чтобы документ условия условия не существовал, но в firestore он содержит документ.Чтобы получить их, есть любой другой метод решения ![enter image description here](https://i.stack.imgur.com/mTcwi.png)
![enter image description here](https://i.stack.imgur.com/auG2r.png)