[ad_1]
My Database is structured like this:
Most important Collections:
- Customers
- Followers(who follows the present person)
The followers assortment shops an inventory of ID’s (every person’s ID). Every of those doc shops an “inbox” sub assortment which shops an inventory of customers ID’s of people that they’ve added as associates, or individuals who have requested to be associates with them.
Every a kind of ID’s shops a “currentStatus” property which is about to “pending” in the event that they have not been added but or “contact” if they’ve (that is how I make the question to fetch both contacts or requests). I then use the ID’s to enter my person assortment to fetch the related customers.
The issue I am having is my operate will get the info however as a result of i am appending it to the revealed array there’s duplicate knowledge (every person reveals up twice on the display screen). So I must be assigning all of the mapped paperwork to the property itself, which I dont know methods to do….
“The issue is that you just’re appending the paperwork to the revealed property. This can result in duplicating the entries.
As an alternative, simply assign the entire mapped paperwork to the emergencyContactUsers property.
Take a look at Mapping Firestore Information in Swift – The Complete Information | Peter Friese for extra particulars about this. I’ve additionally obtained numerous different posts about Firestore and SwiftUI on my weblog that may be helpful.”
-Peter Friese mentioned this and ive been caught making an attempt to do what he mentioned.
@Revealed var userRequestInboxUsers = [User]()
@Revealed var emergencyContactUsers = [User]()
func fetchTheUsersRequests() {
guard let uid = shared.currentUser?.id else { return }
let question = COLLECTION_FOLLOWERS.doc(uid).assortment("inbox").whereField("currentStatus", isEqualTo: "isPending")
print("Question for the requests is about to begin now...")
question.getDocuments { snapshot, error in
if let error = error {
print("There was an error querying the inbox requests: (error.localizedDescription)")
} else {
for request in snapshot!.paperwork {
COLLECTION_USERS.doc(request.documentID).getDocument { snapshot, error in
if let error = error {
print("There was an error fetching the person knowledge: (error)")
} else {
guard let userRequestInInbox = attempt? snapshot?.knowledge(as: Consumer.self) else { return }
self.userRequestInboxUsers.append(userRequestInInbox)
print("Consumer request operate has been ran...")
}
}
}
}
}
}
This operate works completely apart from the truth that it provides me duplicated outcomes.
My func getContacts() primarily is ran the very same approach simply the question is completely different.
A hyperlink to my unique query might be right here: SwiftIU/Firebase: How you can replace lists of customers from Firebase in actual time and have it mirror within the UI?
Any assist can be significantly appreciated!
[ad_2]
