FE_Tech
FE_Tech

Reputation: 1752

CoreData : Custom sort descriptor for fetch in Fetched Results Controller

I have an entity with an attribute called "plainText" which stores text of type "String".

I want to fetch the objects based on a custom sort descriptor which is used in fetchedResultscontroller's fetch.

Example :- I have objects which has plainText containing "He", "When", "Whenever", when I search for words which contains "He", The first object should be the object which has "He" i.e exact match. followed by other matches.

My fetch looks like this

var fetch: NSFetchRequest<CoreNote> = CoreNote.fetchRequest()

fetch.predicate = NSPredicate(format: "plainText CONTAINS[c] %@", searchString)

As I am using fetchedResultsController, I should not process the objects after the fetch happens.

refer this :- https://stackoverflow.com/a/13045887/8409258

Upvotes: 0

Views: 38

Answers (0)

Related Questions