0

I am using a Predicate for filtering a NSArray but, when a create Predicate like this

  NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K contains[c] %@ && %K contains[c] %@ ",
                                                            kUnitUnitcategoryKey,
                                                            @"Blood Pressure Diastolic",
                                                            kUnitUnitNameKey,
                                                            [_txtOxygenSaturationUnit.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];

after this "predicate" string is : "unit_category CONTAINS[c] "Blood Pressure Diastolic" AND unit_name CONTAINS[c] "%" "

NSArray *results = [_arrUnitsName filteredArrayUsingPredicate:predicate];

it will return Zero records.

Now, how can i used % as a string.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
SGDev
  • 2,256
  • 2
  • 13
  • 29

1 Answers1

1

This is an extremely ugly way to write a somewhat complex predicate. You'll find using NSCompoundPredicates are MUCH easier to manage and modify. Simply create your multiple NSPredicates then use an andPredicate to combine all of your predicates.

What is the best way to build a complex NSCompoundPredicate?

As far as the actual question of how can you use % as a string? Test each predicate individually if you are getting zero results for easier debugging and you'll find the issue much easier.

Community
  • 1
  • 1
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
  • It's probably easier just to use a predicate with a block for the second part and then compound them into a single AND predicate. – Fogmeister Nov 12 '14 at 13:42