I have a simple predicate driving me crazy.
NSString *name;
NSDate *myDate;
-(void)fetch:(NSString *)name Date:(NSDate *)myDate
{
...
//predicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name = %@ AND myDate = %@",name,myDate];
[req setPredicate:predicate];
}
-(void)fetch2:(NSString *)predicateStr
{
...
//predicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateStr];
[req setPredicate:predicate];
}
////// call #1/////
[self fetch:name Date:myDate]; //WORKS
////// call #2/////
NSString *predicateStr = [NSString stringWithFormat:@"name = %@ AND myDate = %@",name,myDate];
[self fetch2:predicateStr];
//Call#2 doesn’t work – Can’t parse Date ?? Aren’t they identical? The parameters are the same, no change in values. Note, the Date parameter is the problem, the NSString parameter works fine without the Date.
No, they’re not the same.
For Call #1, here’s what you’re passing in to
+predicateWithFormat::For Call #2, here’s what you’re passing in to
+predicateWithFormat::The first one is a valid predicate format string, and thus it works. The second is not a valid predicate format string, and thus it fails.