Post

Replies

Boosts

Views

Activity

Initializer 'init(_:)' requires that 'Villager' conform to 'StringProtocol'
Hello. I am fairly new to SwiftUI and wondering if someone can help out with this search functionality. I am currently attempting to pull a list from a json file and when setting up the logic for the search, I get Initializer 'init(_:)' requires that 'Villager' conform to 'StringProtocol' I am sure it may be a silly mistake but this is what I have: struct ContentView: View {     let villager: Villager   @State var searchText = ""   @State var searching = false          var body: some View {                  //MARK: - PROPERTIES                  let villagers: [Villager] = Bundle.main.decode("villagers.json")                         //MARK: - BODY         NavigationView {             VStack {                                  VStack(alignment: .leading) {                                          SearchView(searchText: $searchText, searching: $searching)                                          List { //                        ForEach(villagers) { villager in                         ForEach(villager.name({ (theVillagers: String) -> Bool in                             return theVillagers.hasPrefix(searchText) || searchText ==  ""                         }), id: .self) { Villager in                             Text(Villager)                             NavigationLink(destination: VillagerDetailView(villager: Villager)) {                                 VillagerListItemView(villager: Villager)                             }                                 } I think I am getting the error in the ForEach line but not entirely sure. I appreciate the help
1
0
2k
Aug ’21