Hi,
My SwiftUI app is using json to populate a list. I had an array of the names of States that would link to a list of Congressional Representatives from the json file.
When I had the json file stored in my app I was able to filter the results in the NavagationLink by using this below.
Now I have moved the json file online so I can update it regularly, but I cannot use the same method to filter my results.
I tried to use the State name from the json file, but that creates duplicates base on how many reps that State has. I tried a method to remove the duplicate States, but now the link will only show a single representative.
Here is what I am using now.
My SwiftUI app is using json to populate a list. I had an array of the names of States that would link to a list of Congressional Representatives from the json file.
When I had the json file stored in my app I was able to filter the results in the NavagationLink by using this below.
Code Block List { ForEach(self.States, id: \.self) { States in NavigationLink(destination: HouseList(houseData: self.houseData.filter({ $0.stateFullName == States}))) { Text(States) .fontWeight(.regular) .font(.system(size: 14)) } } }.listStyle(GroupedListStyle())
Now I have moved the json file online so I can update it regularly, but I cannot use the same method to filter my results.
I tried to use the State name from the json file, but that creates duplicates base on how many reps that State has. I tried a method to remove the duplicate States, but now the link will only show a single representative.
Here is what I am using now.
Code Block var set: Set<HouseData> = [] let orderedset = fetchHouse.houseData.filter { set.insert($0).inserted } List(orderedset, id: \.self) { houseData in NavigationLink(destination: HouseList(HouseData: houseData)) { Text(houseData.stateFullName) .fontWeight(.regular) .font(.system(size: 14)) } }.listStyle(GroupedListStyle())