0

私は自分のデータベースにFirebaseFirestoreを使用しています。Swift FirestoreドキュメントID取得

私は名前と説明を持つリストの配列を持っています。私はまた、各リストにユニークなdocumentIdをつかみたい。これは可能ですか?

List.swift

struct List { 
    var name:String 
    var description:String 

    var dictionary:[String:Any] { 
     return [ 
      "name":name, 
      "description":description 
     ] 
    } 
} 

私はあなたが実行して文書IDを取得することができた

func getLists() { 
    if Auth.auth().currentUser != nil { 
     db.collection("lists").getDocuments { (querySnapshot, error) in 
      if let error = error { 
       print("Error getting documents: \(error)") 
      } else { 
       self.listArray = querySnapshot!.documents.flatMap({List(dictionary: $0.data())}) 
       DispatchQueue.main.async { 
        self.tableView.reloadData() 
       } 
      } 
     } 
    } 
} 

ListTableViewController.swift ...

for document in querySnapshot!.documents { 
     print("\(document.documentID) => \(document.data())") 
    } 

しかし、私は、これをどのように保存します私のリストは後で電話することができる?

答えて

0

これが最善の方法だと私は肯定的ではありませんが、私はlistArrayに追加され、動作するようです。

self.listArray.append(List(name: document["name"] as! String, description: document["description"] as! String, documentId: document.documentID)) 
関連する問題