I need to generate a predicate from several arrays of values. Therefore, I thought that I could initially form a string with all the values, and then pass this string for use in the predicate, i.e.
NSString* stringForPredicate = [[NSString alloc] init]; if (fromDate != nil) { stringForPredicate = [stringForPredicate stringByAppendingFormat:@"(Date > %@ AND Date < %@)", fromDate, toDate]; }
There are further calculations that I do to form the final line of the predicate.
Now I want the predicate to use this line. I thought something like this would work:
NSPredicate* filterPredicate = [NSPredicate predicateWithFormat:@"%@",stringForPredicate];
But this does not and throws an exception:
'Unable to parse format string'% @ ''
Is there any way to make this work?
thanks,
source share