In my project i have a set of attributes in an entity.One of them is path as string.I want all the records which has my string as a subpath in the path.
Example: Path:/var/mobile/Applications/C4ECC129-36D2-4428-8BB0- 6B1F4C971FC1/Library/Caches/Packages/1000
Mystring : Library/Caches/Packages/1000
I tried using Like and contains as below but failed.
[NSPredicate predicateWithFormat:@"bookPath like[c] '%%%@'",Mystring];
[NSPredicate predicateWithFormat:@"bookPath Contains[cd] '%@'",Mystring];
Can some one help in writing the predicate to fetch those records which contains mystring.
Really helps me a lot.
Tnx in advance
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With