How to filter large content without blocking the main thread?


I’m trying to run searching with keywords in user notes which limited to 2000 characters.
The code below is the NSPredict string I’m using.

            predictString = "content CONTAINS '\(keyword)'"

The filtered data will be populated on a table view, which means the data will be accessed in the main thread.
Thus, my realm object is also created and run in the main thread.
So, here comes the issue, the main thread will be significantly blocked will there are about 1500 records in the database.
I tried to load data in a background thread, but those data can’t be accessed in the main thread since all realm objects required to be accessed in the same thread.
Also, pass those data by ThreadSafeReference is not a good idea because the data would be modified and maintained for quite a while, which is against ThreadSafeReference’s rule.

Is there anyone knows how to solve this?
Really thanks!


Is there anyone can give some hints about how to solve?
I’m really confused. :sob: