0

I understand that Firestore loads data asynchronously, but I want to use these data later and in different ViewControllers. Is there any possibility, to save data in array?

func findPlayers (filters: Dictionary<String, Any>) -> [String] {
    let reference = dataService.instance.dbF.collection("playersStats")

    var query1: Query
    var keysArray = [String?] ()
    var resultIDs = [String] ()

    for key in filters.keys {
        if key != "PositionName" {
            keysArray.append(key)
        }
    }

    if filters.keys.count == 1 {
        if keysArray[0] != nil {
            let value = filters[keysArray[0]!] as? Double
            query1 = reference.whereField(keysArray[0]!, isGreaterThan: value! )

            query1.getDocuments{ (snapshot, err) in
                if let err = err {
                    print("Error getting documents: \(err)")

                } else {
                    for document in snapshot!.documents {
                        let id = String(document.documentID)
                        resultIDs.append(id)

                    }
                }
            }
        }
    }
    return resultIDs
}

I really expect to see array full of data I want to get.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • The documents will be cached locally, so if you do the same query later, and nothing has changed, the results should come from local cache. – Doug Stevenson May 30 '19 at 21:10
  • Yes, I understand, but I need to use these documentIDs for another function call and other calls, and this part of code is just a small piece. I have a lot more calls like .getDocuments, and using it every time doesn't seem like the right way to do it. May be I'm wrong. But is there any chance to store it in array? – Артур Кошут May 30 '19 at 21:28
  • https://stackoverflow.com/questions/25179668/how-to-save-and-read-array-of-array-in-nsuserdefaults-in-swift – canister_exister May 30 '19 at 21:47

0 Answers0