predicate for querying a substring of a string from coredata predicate for querying a substring of a string from coredata sqlite sqlite

predicate for querying a substring of a string from coredata


You need to have a predicate like this

[fecthRequest setPredicate:[NSPredicate predicateWithFormat:@"bookPath endswith[cd] %@", myString]];

or this

[fecthRequest setPredicate:[NSPredicate predicateWithFormat:@"bookPath contains[cd] %@", myString]];

The no results is due to single quotes around your %@. From the documentation (Dynamic Property Names):

string variables are surrounded by quotation marks when they are substituted into a format string using %@

About the predicates I really suggest to use the first, if the sub-path you are looking for it is always in the final part of the original path.

About using predicates, I really suggest to read String Comparisons.

Hope that helps.


Try this:

[NSPredicate predicateWithFormat:@"%K contains %@", @"bookPath", Mystring];