【问题标题】:How to get the arrayList inside documents in firebase firestore in ios using swift如何使用swift在ios的firebase firestore中的文档中获取arrayList
【发布时间】:2018-11-23 07:02:28
【问题描述】:

我是 ios 新手,请考虑..我有集合,因为 organisationStandardTemplate 下面是添加的屏幕截图...我想将来自**roles** array list 的数组列表存储在文档中。 p>

这是 android 代码,它的工作正常,与我在 iOS 中使用的一样 快速的语言..

   FirebaseFirestore db = FirebaseFirestore.getInstance();
    db.collection("organisationStandardTemplate")
        .get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()){
                    if (task.getResult() != null) {
                        for (DocumentSnapshot documentSnapshot : task.getResult()){
                            if (documentSnapshot.exists()) {
                                try {
                                orgTemplate = (ArrayList<HashMap>) documentSnapshot.get("roles");
                                } catch (Exception e){
                                Log.e("Excep", e.getMessage());
                                }
                            }
                        }
                    }
                }
            }
        });

IOS 代码

  func organisationStandardTemplate(){

  var orgTemplate = [AnyObject]() // here i crated my array list

  let db = Firestore.firestore()
        db.collection("organisationStandardTemplate").getDocuments() { (querySnapshot, err) in
            if err != nil{
                // print("\(document.documentID) => \(document.data())")
            }else {

              orgTemplate = //How to get and store into my orgTemplate array list 
                }
            }
        }

  }

文档 https://firebase.google.com/docs/firestore/query-data/get-data

注意:我只有一份文件,但我不想根据 DocumentID 因为我有两个数据库,比如测试和生产所以 每次我无法更改内部代码..

【问题讨论】:

    标签: ios swift google-cloud-firestore


    【解决方案1】:

    声明数组列表

    var orgTemplate = [AnyObject]()
    

     for document in querySnapshot!.documents {
    
              self.orgTemplate =  (document.data()["roles"] as  AnyObject) as! [AnyObject]
              print("resultdefault =sizess     :   \(self.orgTemplate.count)")
              print("resultdefault =orginaldatas     :   \(self.orgTemplate)")
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-03
      • 2022-07-21
      • 2021-02-05
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      相关资源
      最近更新 更多