I am trying to pull information from my Collection called A and want the unique values from the field origin for each document within the collection. So, say if I have three documents B, C, and D with B having and origin of Dominican Republic, C having an origin of United States, and D having an origin of United States. Then I want to display Dominican Republic and United States. I do not want to display Dominican Republic, United States, and United States. I thought putting id: .origin would display unique Origin values, but that is not the case.
My code does not return the unique values of origin:
struct ShowCigarOriginsView: View {
@StateObject var vm = CigarsViewModel()
var body: some View {
ScrollView {
ForEach(vm.cigars, id: \.origin){ cigar in
NavigationLink(destination: Text("TEST"),
label: {
HStack(spacing: 16) {
WebImage(url: URL(string: cigar.nameImageURL))
.resizable()
.scaledToFit()
.frame(width: 100, height: 50)
.clipped()
.cornerRadius(50)
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(Color(.label), lineWidth: 0)
)
VStack{
Text("\(cigar.origin)")
.foregroundColor(Color(.label))
.frame(maxWidth: .infinity, alignment: .center)
}
Spacer()
}.padding(.horizontal)
})
Divider()
.padding(.vertical, 8)
}
}.navigationTitle("Origins")
}
}