Overview: I am trying to get one search bar to search for different properties based on the input text. For example, if I have an address book with 'Names' and 'Numbers', I want a string on the search bar to search 'Names' and if an Int is entered in the search bar, to search 'Numbers'. (just like the iPhone's Phone app)
Steps taken:
1) I have implemented the RealmSearchViewController a la Realm's tutorial. (https://realm.io/news/building-an-ios-search-controller-in-swift/)
2) I have worked out how to assign the searchPropertyKeyPath property via initialisation. (see below if it helps anyone)
required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) self.searchPropertyKeyPath = "PhoneNumber" print("hello") print("Searchbar:", self.searchBar.text) }
Problem: I can't worked out how to a) scan searchbar.text [to check if it is int or string] and then b) modify the searchPropertyKeyPath [to search the appropriate property].
Any views on how to go about this?
(My guess would be to override and then modify the refreshSearchResults() func from the RealmSwiftViewController file. And yes, I have tried this, but ran into coding issues, which I didn't want to bring up in this question)