0

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

2
  • This can’t be done since you can’t have any kind of dynamic logic in a sort descriptor. Commented Feb 20 at 8:19
  • Is there any way I can solve for my use case ? Suggest me an approach if you know. Commented Feb 20 at 9:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.