Snippets Collections
    func getSubAccountData() {
        print("getting data")
        let activityView = activityIndicatorView1()
        activityView.startAnimating()
        let db = Firestore.firestore()
        let owner = Auth.auth().currentUser
        if let owner = owner {
            let docRef = db.collection("Businessowner").document(owner.uid)
            docRef.collection("subaccount").document(subAccountId).addSnapshotListener({ (documentSnapshot, error) in
                guard error == nil else {
                    print("error = \(String(describing: error))")
                    activityView.stopAnimating()
                    return
                }
                if documentSnapshot?.exists == nil {
                    print("Document is empty")
                    activityView.stopAnimating()
                    return
                }
                
                self.imageUrl = documentSnapshot?.get("image") as? String ?? ""
                if self.imageUrl != "" {
                    self.profileImageView.sd_setImage(with: URL(string: self.imageUrl.replacingOccurrences(of: " ", with: "%20")))
                }
                self.nameLabel.text = documentSnapshot?.get("name") as? String ?? ""
                self.emailLabel.text = documentSnapshot?.get("email") as? String ?? ""
                self.phoneNumberLabel.text = documentSnapshot?.get("phoneNumber") as? String ?? ""
                activityView.stopAnimating()
            })
        }
    }
func getDataFromFireStore() {
        print("getting data")
        let activityView = activityIndicatorView()
        activityView.startAnimating()
        let db = Firestore.firestore()
        db.collection("Activities").getDocuments() { (querySnapshot, error) in
            if error != nil {
                print("Error getting documents: \(error!)")
            } else {
                self.activitiesArray.removeAll()
                for document in querySnapshot!.documents {
                    print("for loop")
                    let activities = ActivitiesModel()
                    let data = document.data()
                    activities.title = data["title"] as! String
                    activities.description = data["description"] as! String
                    activities.image_url = data["image_url"] as! String
                    self.activitiesArray.append(activities)
                }
                activityView.stopAnimating()
                self.activitiesTableView.reloadData()
            }
        }
        
    }

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension