1

I'm trying to implement a tableView searching/filtering for my iOS app that uses Realm.io database. There are very few examples of using search function with this database and I'm kinda lost. There are no official guides for filtering results with Realm and the one I was trying to use is this one:

http://www.raywenderlich.com/81615/introduction-to-realm

but it got me nowhere, probably because it has been written 6 months ago and some things have changed in both Swift and Realm since.

I'm mainly interested in implementing UISearchControllerDelegate and UISearchResultsUpdating protocols and changes to tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) associated with implementing a searchBar. Does anyone has a simple working example of a TableViewController with Search using Realm and written in Swift? If not I could try to understand how it is done in obj-c...

kernelpanic
  • 2,876
  • 3
  • 34
  • 58

1 Answers1

1

Since Realm doesn't yet support full-text search, your best bet will likely be to do a BEGINSWITH or CONTAINS query when you go to filter your RLMResults. http://realm.io/news/nspredicate-cheatsheet/ is a handy guide to the different predicates currently supported by Realm.

segiddins
  • 4,110
  • 1
  • 17
  • 22
  • Thanks, that much I gathered. I'm actually using NSPredicate for the query and it works very well. My problem is with implementing the whole thing together in a working example. For instance my problem is I do not know what to do with the results. My tableview either goes ``out of bound`` when I try to reload the tableview or app crashes as soon as I start typing inside the searchBar.. oh, and nice cheatsheet btw! – kernelpanic Mar 30 '15 at 20:56