Hey Brian I am trying to append users from firestore onto cards but am having trouble not sure if i am heading in the right direction or not? trying to append user from firstore to the variable cardUsers. then maybe setting producers = cardusers , but i hitting errors/deadends
var cardUsers = [UserGrapevine]() as [ProducesCardViewModel]
let cardViewModels: [CardViewModel] = {
let producers = [
UserTinder(name: "Kelly", age: 23, profession: "Music DJ", imageNames: ["lady5c","lady4c","kelly1","kelly2","kelly3"]),
UserTinder(name: "Jane", age: 18, profession: "Teacher", imageNames: ["jane1","jane2","jane3"])] as [ProducesCardViewModel]
let viewModels = producers.map({return $0.toCardViewModel()})
return viewModels
}()
func fetchUsersCurrentUserIsFollowing(){
guard let uid = Auth.auth().currentUser?.uid else { return }
let db = Firestore.firestore()
db.collection("Users").document(uid).collection("Following").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
//print("\(document.documentID) => \(document.data())")
let d = document.data()
d.forEach({ (key: String, value: Any) in
print("this is the key",key)
Database.firestorefetchUserForGrapevineCardWithUID(uid: key, completion: { (user) in
//bpxxx
self.cardUsers.append(user)
}
)}
)}
}
}
}
/////////////////////////////////////////////////////////////////////////////
//the func
Database.firestorefetchUserForGrapevineCardWithUID(uid: key, completion: { (user)
//pretty much gives me a user as seen below
let user = UserGrapevine(name: displayName, age: age, profession: occupation, imageNames: ["lady5c"], kmsAway: distanceInKms)
completion(user)
/////////////////////////////////////////////////////////////////////////////