CoreData predicate #"nameOfEntity ==[c] %#" - ios

I got this old project which uses coredata as a persistent store. Problem is it has this kind of predicate for fetching entity:
NSPredicate * predicate = [NSPredicate predicateWithFormat:#"nameOfEntity ==[c] %#", entityName];
I couldn't find what this [c] refers inside this predicate.
Could anyone enlight me into this. I searched everywhere I could.

it means case insensitive. Name, name, NAME will all detected as the same.
String comparisons are by default case and diacritic sensitive. You can modify an operator using the key characters c and d within square braces to specify case and diacritic insensitivity respectively, for example firstName BEGINSWITH[cd] $FIRST_NAME.
source

Related

How do I specify an NSPredicate to match strings that don't start with a letter?

This predicate is used to look up CoreData objects based on their title field. I want to fetch any objects that don't start with a letter character (a-z, A-Z).
I have tried this and variations, but I can't get it to work:
[NSPredicate predicateWithFormat:#"%# MATCHES '^[^a-zA-Z]+.*'", #"title"]
Try using %K to use a key path, rather than %# which uses the value:
[NSPredicate predicateWithFormat:#"%K MATCHES '^[^a-zA-Z].*'", #"title"]
(I also dropped the + modifier as that is unnecessary in your pattern.)
HTH

iOS CoreData convert string for the languages different to english

So the problem is minor. I have NSString the one attribute of my entity. When I work with string on english CoreData store it with the same symbols. But using different languages it starts to store string as:
"\U041c\U0430\U0440\U0442\U0438\U043d - \U0427\U0438\U0441\U0442\U044b\U0439 \U043a\U043e\U0434.2010.pdf"
So what's the problem here: of course I am using predicate for getting some entities and if the predicate equal to the string then it return me object. But when I using not english symbols I get error because the core data automatically convert symbols to the anther string (excluding English).
So what's the steps to fix it? Do I need to check the language before using predicate or there is another simple solution that can help me?
So the predicate looks like:
NSPredicate *predicate
= [NSPredicate predicateWithFormat:#"%K == %# AND \
%K == %#",
kPNFolder_Path, folderPath,
kPNFile_FileName, #"China symbols or Cyrillic symbols here"];
But core data store it as I have described above. Of course it will not return any values, because there is no matches, because of conversation symbols to the unicode after set value to the entity.

NSPredicate omits special characters like á â á in filterContentForSearchText method

I am developing an app with an UISearchBar and I need to filter some names with special characters like à, è, ê and so on.. but if I don't type the correct string with the special character it doesn't appear.
Ex: If I am looking for cómodo word I can't find this word if I don't type exactly có
How could I get that word without type that special characters? for example typing just co.
This is my NSPredicate:
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:#"SELF.word BEGINSWITH[c] %#",
searchText];
Thank you
Ignore diacrtical needs to be specified, "[cd]" instead of "[c]".
See NSHipster: NSPredicate.
NSComparisonPredicate Options:
NSDiacriticInsensitivePredicateOption: A diacritic-insensitive predicate. You represent this option in a predicate format string using a [d] following a string operation (for example, "naïve" like[d] "naive").
Such a common error, it kept me from finding my Metro Station in Paris.

NSPredicate to Match the backslash

I want to fetch entity by name matching the string \\xxxx\\yyyy\\zzzz from core data so i have used NSPredicate like NSPredicate *myPredicate = [NSPredicate predicateWithFormat:" name LIKE %#", \\xxxx\\yyyy\\zzzz]; But returns null for some times.I doubt that issue with backslashes so please help me any one.Is any way to fetch this entity from core data?
"LIKE" in a predicate does a simple wildcard matching (with ? and *).
As a consequence, the backslash character has a special meaning and has to be escaped
twice (once for the string literal and once for the "LIKE" operator):
[NSPredicate predicateWithFormat:"name LIKE %#", #"\\\\xxxx\\\\yyyy\\\\zzzz"]
But if you don't need the wildcard matching then use "==" (or "BEGINSWITH", "CONTAINS") instead:
[NSPredicate predicateWithFormat:"name == %#", #"\\xxxx\\yyyy\\zzzz"]

predicate for querying a substring of a string from coredata

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.
Try this:
[NSPredicate predicateWithFormat:#"%K contains %#", #"bookPath", Mystring];

Resources