Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPredicate contains string lowercase

I'm developing an iOS application with iOS SDK 6.0 and XCode 4.5.2. My target development is 4.3.

I'm using Core Data to manage my data. Now I have this NSPredicate to search shops:

if ((shopSearchBar.text != nil) && ([shopSearchBar.text length] > 0))
{
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name = %@",shopSearchBar.text];
    [fetchRequest setPredicate:predicate];
}

This is Shop entity:

enter image description here

I have to convert name to lowercase and see if it contains shopSearchBar.text in lowercase format.

Example:

I have these four shops:

  • Shop1
  • shop 1
  • my shop
  • Shop

If user search text is 'shop', it must returns all of them.

Do you know how to do that?

like image 915
VansFannel Avatar asked Jan 30 '13 18:01

VansFannel


1 Answers

This is how I've solved my problem:

if ((shopSearchBar.text != nil) && ([shopSearchBar.text length] > 0))
{
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@",
                              shopSearchBar.text];
    [fetchRequest setPredicate:predicate];
}
like image 163
VansFannel Avatar answered Sep 22 '22 15:09

VansFannel